Skip to content

Honor quantization_config#692

Merged
Blaizzy merged 4 commits intoBlaizzy:mainfrom
pcuenca:quantization_config
Feb 11, 2026
Merged

Honor quantization_config#692
Blaizzy merged 4 commits intoBlaizzy:mainfrom
pcuenca:quantization_config

Conversation

@pcuenca
Copy link
Contributor

@pcuenca pcuenca commented Jan 28, 2026

This makes it possible to load transformers quantized weights.

This is another mismatch I found while working on #689. I was puzzled that I had to use QuantizedSwitchLinear explicitly in order to be able to load the weights, whereas this was not necessary in mlx_lm. The quantization process immediately performed after sanitization is driven by the existence of quantization_config, and it adapts the weights accordingly so they have .scales and .biases.

Extracting as a separate PR for discussion, maybe I missed some side effects.

This makes it possible to load transformers quantized weights
@pcuenca
Copy link
Contributor Author

pcuenca commented Jan 28, 2026

After this commit, the following simplification can be made: cacb9c2, part of the kimi PR.

(and we could probably still simplify the sanitize method a bit)

config["quantization"] = quantization
config["quantization_config"] = quantization

if (quantization := config.get("quantization", None)) is not None:
Copy link
Owner

@Blaizzy Blaizzy Jan 28, 2026

Choose a reason for hiding this comment

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

I believe the new code above should be here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a bit confusing 😅. quantization is first read in L140 (which was already there). If it exists, it's a MLX-style quantization definition. If it doesn't, then we check if quantization_config exists, convert it to quantization format and store it in the config object. Perhaps we could remove L140 and just check if config has the quantization attribute in line 217.

Copy link
Owner

Choose a reason for hiding this comment

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

Let's refactor then 😎

I think this could start at line 241.

So all the quantisation logic is clear in one place

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted the distant quantization line from L140 and simplified slightly.

@pcuenca pcuenca requested a review from Blaizzy February 2, 2026 17:47
Copy link
Owner

@Blaizzy Blaizzy left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@Blaizzy Blaizzy merged commit dd7cef1 into Blaizzy:main Feb 11, 2026
1 check passed
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