Skip to content

fix(quantization): export root-module weights in graph CoreML#15

Open
eyupcanakman wants to merge 1 commit into
apple:mainfrom
eyupcanakman:fix/graph-root-module-weight
Open

fix(quantization): export root-module weights in graph CoreML#15
eyupcanakman wants to merge 1 commit into
apple:mainfrom
eyupcanakman:fix/graph-root-module-weight

Conversation

@eyupcanakman

Copy link
Copy Markdown
Contributor

Quantizer.finalize(backend=ExportBackend.CoreML) crashes on a weight that is a parameter of the root module, such as a bare nn.Linear.

_get_weight_input_names splits the weight's get_attr target into a module name and a parameter name on the last dot. A root-module parameter exports with a dot-less target (weight), so there is no dot to split on and the function raised:

ValueError: Invalid weight target path: weight

A weight on a child module (conv.weight, layer1.0.weight) splits cleanly and works, and so does the same model in eager mode. The fix treats a dot-less target as a parameter on the root module, returning "" as the module name, which _get_weight_module already resolves through the "" key in named_modules(). The new test exports a bare nn.Linear to Core ML.

A weight on the root module (a bare nn.Linear) exports with a dot-less
get_attr target, which _get_weight_input_names rejected with "Invalid
weight target path". Treat a dot-less target as a root-module parameter
(module name ""), which _get_weight_module already resolves.
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.

2 participants