-
Notifications
You must be signed in to change notification settings - Fork 599
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 a new compression pass for activation quantization. #2216
base: main
Are you sure you want to change the base?
Conversation
) | ||
from coremltools.converters.mil.mil.passes.helper import _check_child_op_type, block_context_manager | ||
from coremltools.converters.mil.mil.passes.pass_registry import register_pass | ||
#from coremltools.optimize.coreml._utils import quantize_weight |
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.
Remove this line
Can you add an overview of this change to the description of the pull request? Also please add unit tests for this new functionality. |
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.
+1 on unit test suggested by Toby.
As this is a pretty big change, in addition to the unit test, we also need e2e tests.
|
||
# try pattern I | ||
# `dequant` -> `conv` | ||
if self._try_match_and_transform_pattern(op, block, config, visited_ops): |
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.
This is going to slow down the graph pass, please don't break early
# visited_ops.add(op) | ||
return True | ||
|
||
# try pattern II |
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 is pattern II?
# `quantize` -> `dequant` | ||
if self._try_match_and_transform_pattern(op, block, activation_stats, visited_ops): | ||
# has to break as the downstream iterator is affected | ||
# visited_ops.add(op) |
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.
same commet
with mb.scope(ScopeInfo(source=ScopeSource.COREMLTOOLS_GRAPH_PASS, data=[str(self)])): | ||
self.apply(prog, sample_data) | ||
|
||
def __str__(self): |
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.
These two classes are pretty duplicated,
and the __str__
, set_options
could share the same code from AbstractGraphPass
.
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.
And sample_data
, config
both can just be the graph option right?
So we could still re-use the original AbstractGraphPass
class ...
# Insert trailing quantize/dequantize pair to valid patterns. | ||
print("Running compression pass activations_quantization phase 2/4 ...") | ||
graph_pass = PASS_REGISTRY["compression::insert_quantize_dequantize"] | ||
graph_pass(prog, config) |
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.
Yeah, we can just set the config / sample_data as graph pass object's class member I think ....
Prob no need to pass them as inputs for the apply
...
|
||
# Graph pass II | ||
# Insert trailing quantize/dequantize pair to valid patterns. | ||
print("Running compression pass activations_quantization phase 2/4 ...") |
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.
please use logger
) | ||
|
||
self.__cached_models[model_key] = model | ||
# print(f"Created model with intermediate outputs={intermediate_output_names}") |
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.
Lots of debugging codes in this PR need to be removed ..
No description provided.