Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yixingli-apple
Copy link

No description provided.

)
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line

@TobyRoseman
Copy link
Collaborator

Can you add an overview of this change to the description of the pull request?

Also please add unit tests for this new functionality.

Copy link
Collaborator

@junpeiz junpeiz left a 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):
Copy link
Collaborator

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
Copy link
Collaborator

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)
Copy link
Collaborator

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):
Copy link
Collaborator

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.

Copy link
Collaborator

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)
Copy link
Collaborator

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 ...")
Copy link
Collaborator

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}")
Copy link
Collaborator

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 ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants