-
Notifications
You must be signed in to change notification settings - Fork 52
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
add substitution for functional linear #1266
base: main
Are you sure you want to change the base?
Conversation
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 about torch.nn.functional.conv2d
and it's friends?
from model_compression_toolkit.logger import Logger | ||
|
||
|
||
class FunctionalLinear(common.BaseSubstitution): |
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.
just import BaseSubstitution from common
|
||
class FunctionalLinear(common.BaseSubstitution): | ||
""" | ||
Replace functional layer_norm with LayerNorm. |
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.
layer_norm?
Logger.critical(f'Weight input missing for node {func_node.name}.') # pragma: no cover | ||
|
||
weight = func_node.weights[1] | ||
bias = func_node.weights.get(2, 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.
make sure the bias positional weight is saved as 2 even when the linear is called with bias as kwarg
name=func_node.name, | ||
framework_attr=framework_attr, | ||
input_shape=func_node.input_shape[0], | ||
output_shape=tuple(func_node.output_shape[0]), |
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.
why not just output_shape=func_node.output_shape
?
|
||
def forward(self, x): | ||
x = F.linear(x, self.fc1.weight, self.fc1.bias) | ||
y = F.linear(x, self.fc2.weight, self.fc2.bias) |
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.
change to:
y = F.linear(x, bias=self.fc2.bias, weight=self.fc2.weight)
to make sure everything still works
Pull Request Description:
Checklist before requesting a review: