Conversation
Two fixes to the quantization path, plus tests covering both. quantize_model/1 built its rewriter as a five-arity closure that was then partially applied, and in doing so only forwarded :units and :use_bias to the replacement layer. Any other metadata on the dense layer it replaced was silently dropped. The rewriter is now an inline two-arity function that passes the original layer's meta through. QTensor.from_tensor/2 rejected every float tensor that was not f32, raising "expected a float tensor" for f64 and bf16 inputs - which are float tensors, so the message was misleading as well as wrong. Such inputs are now cast to f32 before quantizing. The quantization kernel is also collapsed from two eager transforms (choose_quantization_params_affine and quantize_affine) into a single defnp, dropping the mapping_type, preserve_zero and zero_point_domain options that only ever accepted one value. The math is unchanged: on random weight matrices the resulting value, scale and zero_point are bit-identical to the previous implementation, apart from occasional single-LSB differences at rounding ties (91 of 15360 elements over 30 random matrices, never more than 1 LSB). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
polvalente
reviewed
Aug 16, 2026
Comment on lines
+87
to
+92
| min_val = Nx.reduce_min(input, axes: opts[:reduction_dims]) | ||
| max_val = Nx.reduce_max(input, axes: opts[:reduction_dims]) | ||
|
|
||
| {shape_for_reduction, reduction_dims} = get_reduction_params(block_size, Nx.shape(input)) | ||
| input = Nx.reshape(input, shape_for_reduction) | ||
|
|
||
| min_val = Nx.reduce_min(input, axes: reduction_dims, keep_axes: false) | ||
| max_val = Nx.reduce_max(input, axes: reduction_dims, keep_axes: false) | ||
| min_val_neg = Nx.min(min_val, 0) | ||
| max_val_pos = Nx.max(max_val, 0) | ||
| max_val_pos = Nx.max(Nx.negate(min_val_neg), max_val_pos) |
Member
There was a problem hiding this comment.
isn't all of this just Nx.reduce_max(Nx.abs(input), axes: opts[:reduction_dims])?
polvalente
reviewed
Aug 16, 2026
Comment on lines
+103
to
+104
| input | ||
| |> Nx.multiply(Nx.divide(1, scale_r)) |
Member
There was a problem hiding this comment.
Suggested change
| input | |
| |> Nx.multiply(Nx.divide(1, scale_r)) | |
| input | |
| |> Nx.divide(scale_r) |
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.
No description provided.