-
Notifications
You must be signed in to change notification settings - Fork 54
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
[IR] Implement register_initializer #1941
Conversation
❌ 16 Tests Failed:
View the full list of 3 ❄️ flaky tests
To view more test analytics, go to the Test Analytics Dashboard |
ValueError: If the value does not have its ``.const_value`` set. | ||
""" | ||
if value.name in self._initializers: | ||
if self._initializers[value.name] is not value: |
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.
- Not necessarily in this PR, but would be nice to have a method to reuse initializers, especially for common duplicated constants, like 0, 1 or even shapes like (batchsize, seqlen, hiddensize).
- On a related note, for very small tensors, we could replace the
is
comparison above with a value-equality check. May not be that important if we add a separate utility to reuse initializers as above, but if not this could serve so approximately.
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.
I think this can be a graph pass too (dedup initializers)
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.
) | ||
if not value.name: | ||
raise ValueError(f"Initializer must have a name: {value!r}") | ||
if value.producer() is not None: |
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.
I wonder if we should support promotion of a Constant
node to an initializer (later on perhaps; could be an option in this method or a separate one).
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.
I think that can be a graph 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.
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.
Should we update this usage to exporter in terms of robustness?
Sure, we can do that |
Implement
register_initializer(value)
onGraph
for robustly adding an initializer to the graph. Users can also directly modify thegraph.initializers
dictionary, but this method does more comprehensive checks before adding, and calling this method is simpler than modifying the dictionary.The method could be in the
convenience
too, but I put it here due to its relevance and for better discoverability.