Core ML: stop the gather opt-out from failing tied embeddings - #21969
Open
john-rocky wants to merge 1 commit into
Open
Core ML: stop the gather opt-out from failing tied embeddings#21969john-rocky wants to merge 1 commit into
john-rocky wants to merge 1 commit into
Conversation
The linear quantizer config opts gathers out so embedding tables are not compressed by it. When a model ties its embedding table to its output projection, that one constant reaches the compressor configured two ways at once — quantized as a linear weight, exempt as a gather table — and coremltools refuses the conflict rather than resolving it. The opt-out then does not skip the table, it fails the whole lowering, which is how a common LLM shape becomes unlowerable with coreml_quantize set. Gathers that share their constant with an op of another type are now configured the same way as the op they share it with; every other gather keeps the opt-out. A model whose program is unavailable is left exactly as before. Fixes pytorch#21856
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21969
Note: Links to docs will display an error until the docs builds have been completed.
|
This PR needs a
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21856.
What happens today
op_linear_quantizer_configis applied withop_type_configs={"gather": None}, so thatembedding tables are not compressed by the linear quantizer. When a model ties its embedding
table to its output projection — one weight, two consumers — that constant reaches the
compressor configured two ways at once: quantized as a
linearweight, exempt as agathertable. coremltools refuses the conflict rather than resolving it:
So the opt-out does not skip the table. It fails the whole lowering, and a very common LLM
shape cannot be lowered at all with
coreml_quantizeset.The change
Gathers whose constant is also consumed by an op of another type are named in
op_name_configswith the same config as the op they share it with, so the constant is seenone way. Every other gather keeps the opt-out, and a model whose MIL program is not available
returns no names, which leaves the behaviour exactly as it was.
Checking it
The new test in
test_coreml_partitioner.pylowers a two-layer model twice, tied and untied.Against
mainthe tied case raises the error above; with this change both lower. The untiedcase passes either way, which is the point — the opt-out still applies where it always did.
Measured on macOS arm64, coremltools 9.0.