Repository navigation
Commit 0447246
authored
Core ML: stop the gather opt-out from failing tied embeddings (pytorch#21969)
Fixes pytorch#21856.
### What happens today
`op_linear_quantizer_config` is applied with `op_type_configs={"gather":
None}`, so that
embedding 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 `linear` weight,
exempt as a `gather`
table. coremltools refuses the conflict rather than resolving it:
```
ValueError: compression config conflict detected between ops
%aten_embedding_default_...: gather(x=%p_out_weight_to_fp16, ...)
and
%aten_mm_default...: linear(x=..., weight=%p_out_weight_to_fp16, ...)
... has config None while ... has OpLinearQuantizerConfig(mode='LINEAR_SYMMETRIC', ...)
```
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_quantize` set.
### The change
Gathers whose constant is also consumed by an op of another type are
named in
`op_name_configs` with the same config as the op they share it with, so
the constant is seen
one 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.py` lowers a two-layer model
twice, tied and untied.
Against `main` the tied case raises the error above; with this change
both lower. The untied
case passes either way, which is the point — the opt-out still applies
where it always did.
Measured on macOS arm64, coremltools 9.0.1 parent 422e07c commit 0447246
2 files changed
Lines changed: 79 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
39 | 70 | | |
40 | 71 | | |
41 | 72 | | |
| |||
579 | 610 | | |
580 | 611 | | |
581 | 612 | | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
582 | 619 | | |
583 | 620 | | |
584 | 621 | | |
| 622 | + | |
585 | 623 | | |
586 | 624 | | |
587 | 625 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
433 | 433 | | |
434 | 434 | | |
435 | 435 | | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
436 | 476 | | |
437 | 477 | | |
438 | 478 | | |
| |||
532 | 572 | | |
533 | 573 | | |
534 | 574 | | |
| 575 | + | |
535 | 576 | | |
536 | 577 | | |
0 commit comments