-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Fix path of the states in SeedGenerator
and tracking of torch_params
#19495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1ccadd2
ca5e7e7
a00089f
19c20b8
0619222
20e015a
7db40be
6176411
eefcc8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,7 +147,6 @@ def __init__( | |
self.sparse = sparse | ||
|
||
if self.bin_boundaries: | ||
self.built = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explicitly set I'm unsure where the issue is but it should be acceptable to leave There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from keras import layers
inputs = layers.Input([2])
layer = layers.Dropout(rate=0.2)
layer(inputs)
assert len(layer.torch_params) == len(layer.variables) This script will fail at the master branch but work fine in this pr. |
||
self.summary = None | ||
else: | ||
self.summary = np.array([[], []], dtype="float32") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,6 @@ def __init__(self, rate, noise_shape=None, seed=None, **kwargs): | |
if rate > 0: | ||
self.seed_generator = backend.random.SeedGenerator(seed) | ||
self.supports_masking = True | ||
self.built = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
|
||
def call(self, inputs, training=False): | ||
if training and self.rate > 0: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,3 +280,11 @@ def _post_build(self): | |
def _setattr_hook(self, name, value): | ||
"""Can be overridden for per backend post build actions.""" | ||
return name, value | ||
|
||
def _post_track_variable(self, variable): | ||
"""Can be overridden for per backend post track actions.""" | ||
pass | ||
|
||
def _post_untrack_variable(self, variable): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two hooks have been introduced to enable the postprocessing of |
||
"""Can be overridden for per backend post untrack actions.""" | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dict is more readable, but it's unsafe -- there's no guarantee that variable names are unique within a model (except for Functional models). It's entirely possible to create models with duplicate variable paths, which would cause tracking issues above. So the list is preferable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be safe to use
id(variable)
as a key fortorch.nn.ParameterDict
. I believeBaseOptimizer
adopts the same approach to get the mapping of variables.I could not find a solution for safely adding/removing the variable from
torch.nn.ParameterList
(
in
andremove
ofKerasVariable
are not supported)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the original issue with using a list though?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that
torch.nn.ParameterList
cannot remove elements. This will cause failure in the int8 quantization because we need to remove the old floating_kernel
.Also, it is hard to determine if it is safe to
append
a new variable because we cannot check whether the item is already in the list.master
The biggest issue is that
zero_grad()
will fail to reset the uncaptured variables.I believe the currect LoRA implementation will not be trained correctly on torch backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To demonstrate the error of
zero_grad
using LoRA: