Skip to content

Refactor quantization into a shared extension/llm/export/quant package (#21044)#21044

Merged
metascroy merged 1 commit into
pytorch:mainfrom
metascroy:export-D112867629
Jul 21, 2026
Merged

Refactor quantization into a shared extension/llm/export/quant package (#21044)#21044
metascroy merged 1 commit into
pytorch:mainfrom
metascroy:export-D112867629

Conversation

@metascroy

@metascroy metascroy commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary:

Consolidates the quantization/packing logic that was previously duplicated
across per-model directories into a single reusable package under
extension/llm/export/quant, and introduces a model-free checkpoint loader.

Key changes:

  • New extension/llm/export/quant package exposing a stable API:
    • convert.py: Convert, to_exportable/to_default, fuse_along_output, identity
    • quantize.py: quantize_model/quantize_weight/quantize_stream + dequantize
    • recipe.py: QuantConfig / QuantRecipe / QuantRule
  • New extension/llm/export/load.py: model-free (iter_checkpoint) and
    model-aware (load_checkpoint) readers that stream GGUF / safetensors weights,
    remap names to FQNs, and wrap quantized subclasses in portable Exportable*
    form. Backend-specific layout (CUDA coalesced int4, MLX gather buffers) is a
    separate terminal pass.
  • Extended int4.py / gguf.py to plug into the shared conversion path.
  • Removed the old per-model examples/models/gemma4_31b/quant/ packers
    (pack.py, pack_cuda.py, pack_mlx.py) and moved packing into
    examples/models/gemma4_31b/cuda_packers.py, wiring gemma4_31b and
    qwen3_5_moe onto the shared package.
  • Added unit tests for the new package and the gemma4_31b packers/pipelines.

Reviewed By: Gasoonjia

Differential Revision: D112867629

@pytorch-bot

pytorch-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21044

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 1 New Failure, 1 Unrelated Failure, 3 Unclassified Failures

As of commit d18198d with merge base 564e655 (image):

NEW FAILURE - The following job has failed:

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 20, 2026
@meta-codesync

meta-codesync Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@metascroy has exported this pull request. If you are a Meta employee, you can view the originating Diff in D112867629.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

from executorch.backends.cuda.quantize_op_dispatch.int4_dispatch import _dequant_matmul
from executorch.examples.models.gemma4_31b.quant.pack_cuda import pack_linear_for_cuda
from executorch.examples.models.gemma4_31b.quant.quantize import (
from executorch.examples.models.gemma4_31b.cuda_packers import pack_linear_for_cuda

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if the cuda packers are shared (at least across gemma4_31b and
qwen3_5_moe), why not also have this in something like extension.llm.cuda_packers?

metascroy added a commit to metascroy/executorch that referenced this pull request Jul 20, 2026
pytorch#21044)

Summary:
Pull Request resolved: pytorch#21044

Consolidates the quantization/packing logic that was previously duplicated
across per-model directories into a single reusable package under
extension/llm/export/quant, and introduces a model-free checkpoint loader.

Key changes:
- New extension/llm/export/quant package exposing a stable API:
  - convert.py: Convert, to_exportable/to_default, fuse_along_output, identity
  - quantize.py: quantize_model/quantize_weight/quantize_stream + dequantize
  - recipe.py: QuantConfig / QuantRecipe / QuantRule
- New extension/llm/export/load.py: model-free (iter_checkpoint) and
  model-aware (load_checkpoint) readers that stream GGUF / safetensors weights,
  remap names to FQNs, and wrap quantized subclasses in portable Exportable*
  form. Backend-specific layout (CUDA coalesced int4, MLX gather buffers) is a
  separate terminal pass.
- Extended int4.py / gguf.py to plug into the shared conversion path.
- Removed the old per-model examples/models/gemma4_31b/quant/ packers
  (pack.py, pack_cuda.py, pack_mlx.py) and moved packing into
  examples/models/gemma4_31b/cuda_packers.py, wiring gemma4_31b and
  qwen3_5_moe onto the shared package.
- Added unit tests for the new package and the gemma4_31b packers/pipelines.

Differential Revision: D112867629
@meta-codesync meta-codesync Bot changed the title Refactor quantization into a shared extension/llm/export/quant package Refactor quantization into a shared extension/llm/export/quant package (#21044) Jul 20, 2026
@metascroy
metascroy force-pushed the export-D112867629 branch from 72badd5 to a181426 Compare July 20, 2026 20:42
metascroy added a commit to metascroy/executorch that referenced this pull request Jul 20, 2026
pytorch#21044)

Summary:
Pull Request resolved: pytorch#21044

Consolidates the quantization/packing logic that was previously duplicated
across per-model directories into a single reusable package under
extension/llm/export/quant, and introduces a model-free checkpoint loader.

Key changes:
- New extension/llm/export/quant package exposing a stable API:
  - convert.py: Convert, to_exportable/to_default, fuse_along_output, identity
  - quantize.py: quantize_model/quantize_weight/quantize_stream + dequantize
  - recipe.py: QuantConfig / QuantRecipe / QuantRule
- New extension/llm/export/load.py: model-free (iter_checkpoint) and
  model-aware (load_checkpoint) readers that stream GGUF / safetensors weights,
  remap names to FQNs, and wrap quantized subclasses in portable Exportable*
  form. Backend-specific layout (CUDA coalesced int4, MLX gather buffers) is a
  separate terminal pass.
- Extended int4.py / gguf.py to plug into the shared conversion path.
- Removed the old per-model examples/models/gemma4_31b/quant/ packers
  (pack.py, pack_cuda.py, pack_mlx.py) and moved packing into
  examples/models/gemma4_31b/cuda_packers.py, wiring gemma4_31b and
  qwen3_5_moe onto the shared package.
- Added unit tests for the new package and the gemma4_31b packers/pipelines.

Differential Revision: D112867629
@metascroy
metascroy force-pushed the export-D112867629 branch from a181426 to f8a5ace Compare July 20, 2026 20:48
metascroy added a commit to metascroy/executorch that referenced this pull request Jul 20, 2026
pytorch#21044)

Summary:
Pull Request resolved: pytorch#21044

Consolidates the quantization/packing logic that was previously duplicated
across per-model directories into a single reusable package under
extension/llm/export/quant, and introduces a model-free checkpoint loader.

Key changes:
- New extension/llm/export/quant package exposing a stable API:
  - convert.py: Convert, to_exportable/to_default, fuse_along_output, identity
  - quantize.py: quantize_model/quantize_weight/quantize_stream + dequantize
  - recipe.py: QuantConfig / QuantRecipe / QuantRule
- New extension/llm/export/load.py: model-free (iter_checkpoint) and
  model-aware (load_checkpoint) readers that stream GGUF / safetensors weights,
  remap names to FQNs, and wrap quantized subclasses in portable Exportable*
  form. Backend-specific layout (CUDA coalesced int4, MLX gather buffers) is a
  separate terminal pass.
- Extended int4.py / gguf.py to plug into the shared conversion path.
- Removed the old per-model examples/models/gemma4_31b/quant/ packers
  (pack.py, pack_cuda.py, pack_mlx.py) and moved packing into
  examples/models/gemma4_31b/cuda_packers.py, wiring gemma4_31b and
  qwen3_5_moe onto the shared package.
- Added unit tests for the new package and the gemma4_31b packers/pipelines.

Differential Revision: D112867629
@metascroy
metascroy force-pushed the export-D112867629 branch from f8a5ace to 577db1d Compare July 20, 2026 21:32
metascroy added a commit to metascroy/executorch that referenced this pull request Jul 20, 2026
pytorch#21044)

Summary:
Pull Request resolved: pytorch#21044

Consolidates the quantization/packing logic that was previously duplicated
across per-model directories into a single reusable package under
extension/llm/export/quant, and introduces a model-free checkpoint loader.

Key changes:
- New extension/llm/export/quant package exposing a stable API:
  - convert.py: Convert, to_exportable/to_default, fuse_along_output, identity
  - quantize.py: quantize_model/quantize_weight/quantize_stream + dequantize
  - recipe.py: QuantConfig / QuantRecipe / QuantRule
- New extension/llm/export/load.py: model-free (iter_checkpoint) and
  model-aware (load_checkpoint) readers that stream GGUF / safetensors weights,
  remap names to FQNs, and wrap quantized subclasses in portable Exportable*
  form. Backend-specific layout (CUDA coalesced int4, MLX gather buffers) is a
  separate terminal pass.
- Extended int4.py / gguf.py to plug into the shared conversion path.
- Removed the old per-model examples/models/gemma4_31b/quant/ packers
  (pack.py, pack_cuda.py, pack_mlx.py) and moved packing into
  examples/models/gemma4_31b/cuda_packers.py, wiring gemma4_31b and
  qwen3_5_moe onto the shared package.
- Added unit tests for the new package and the gemma4_31b packers/pipelines.

Differential Revision: D112867629
@metascroy
metascroy force-pushed the export-D112867629 branch from 577db1d to a6129f4 Compare July 20, 2026 21:44
metascroy added a commit to metascroy/executorch that referenced this pull request Jul 20, 2026
pytorch#21044)

Summary:
Pull Request resolved: pytorch#21044

Consolidates the quantization/packing logic that was previously duplicated
across per-model directories into a single reusable package under
extension/llm/export/quant, and introduces a model-free checkpoint loader.

Key changes:
- New extension/llm/export/quant package exposing a stable API:
  - convert.py: Convert, to_exportable/to_default, fuse_along_output, identity
  - quantize.py: quantize_model/quantize_weight/quantize_stream + dequantize
  - recipe.py: QuantConfig / QuantRecipe / QuantRule
- New extension/llm/export/load.py: model-free (iter_checkpoint) and
  model-aware (load_checkpoint) readers that stream GGUF / safetensors weights,
  remap names to FQNs, and wrap quantized subclasses in portable Exportable*
  form. Backend-specific layout (CUDA coalesced int4, MLX gather buffers) is a
  separate terminal pass.
- Extended int4.py / gguf.py to plug into the shared conversion path.
- Removed the old per-model examples/models/gemma4_31b/quant/ packers
  (pack.py, pack_cuda.py, pack_mlx.py) and moved packing into
  examples/models/gemma4_31b/cuda_packers.py, wiring gemma4_31b and
  qwen3_5_moe onto the shared package.
- Added unit tests for the new package and the gemma4_31b packers/pipelines.

Differential Revision: D112867629
@metascroy
metascroy force-pushed the export-D112867629 branch from a6129f4 to f8cae64 Compare July 20, 2026 22:24
metascroy added a commit to metascroy/executorch that referenced this pull request Jul 20, 2026
pytorch#21044)

Summary:
Pull Request resolved: pytorch#21044

Consolidates the quantization/packing logic that was previously duplicated
across per-model directories into a single reusable package under
extension/llm/export/quant, and introduces a model-free checkpoint loader.

Key changes:
- New extension/llm/export/quant package exposing a stable API:
  - convert.py: Convert, to_exportable/to_default, fuse_along_output, identity
  - quantize.py: quantize_model/quantize_weight/quantize_stream + dequantize
  - recipe.py: QuantConfig / QuantRecipe / QuantRule
- New extension/llm/export/load.py: model-free (iter_checkpoint) and
  model-aware (load_checkpoint) readers that stream GGUF / safetensors weights,
  remap names to FQNs, and wrap quantized subclasses in portable Exportable*
  form. Backend-specific layout (CUDA coalesced int4, MLX gather buffers) is a
  separate terminal pass.
- Extended int4.py / gguf.py to plug into the shared conversion path.
- Removed the old per-model examples/models/gemma4_31b/quant/ packers
  (pack.py, pack_cuda.py, pack_mlx.py) and moved packing into
  examples/models/gemma4_31b/cuda_packers.py, wiring gemma4_31b and
  qwen3_5_moe onto the shared package.
- Added unit tests for the new package and the gemma4_31b packers/pipelines.

Reviewed By: Gasoonjia

Differential Revision: D112867629
@metascroy
metascroy force-pushed the export-D112867629 branch from f8cae64 to 6bc7094 Compare July 20, 2026 23:19
metascroy added a commit to metascroy/executorch that referenced this pull request Jul 21, 2026
pytorch#21044)

Summary:
Pull Request resolved: pytorch#21044

Consolidates the quantization/packing logic that was previously duplicated
across per-model directories into a single reusable package under
extension/llm/export/quant, and introduces a model-free checkpoint loader.

Key changes:
- New extension/llm/export/quant package exposing a stable API:
  - convert.py: Convert, to_exportable/to_default, fuse_along_output, identity
  - quantize.py: quantize_model/quantize_weight/quantize_stream + dequantize
  - recipe.py: QuantConfig / QuantRecipe / QuantRule
- New extension/llm/export/load.py: model-free (iter_checkpoint) and
  model-aware (load_checkpoint) readers that stream GGUF / safetensors weights,
  remap names to FQNs, and wrap quantized subclasses in portable Exportable*
  form. Backend-specific layout (CUDA coalesced int4, MLX gather buffers) is a
  separate terminal pass.
- Extended int4.py / gguf.py to plug into the shared conversion path.
- Removed the old per-model examples/models/gemma4_31b/quant/ packers
  (pack.py, pack_cuda.py, pack_mlx.py) and moved packing into
  examples/models/gemma4_31b/cuda_packers.py, wiring gemma4_31b and
  qwen3_5_moe onto the shared package.
- Added unit tests for the new package and the gemma4_31b packers/pipelines.

Reviewed By: Gasoonjia

Differential Revision: D112867629
@metascroy
metascroy force-pushed the export-D112867629 branch from 6bc7094 to 7b40560 Compare July 21, 2026 00:38
pytorch#21044)

Summary:
Pull Request resolved: pytorch#21044

Consolidates the quantization/packing logic that was previously duplicated
across per-model directories into a single reusable package under
extension/llm/export/quant, and introduces a model-free checkpoint loader.

Key changes:
- New extension/llm/export/quant package exposing a stable API:
  - convert.py: Convert, to_exportable/to_default, fuse_along_output, identity
  - quantize.py: quantize_model/quantize_weight/quantize_stream + dequantize
  - recipe.py: QuantConfig / QuantRecipe / QuantRule
- New extension/llm/export/load.py: model-free (iter_checkpoint) and
  model-aware (load_checkpoint) readers that stream GGUF / safetensors weights,
  remap names to FQNs, and wrap quantized subclasses in portable Exportable*
  form. Backend-specific layout (CUDA coalesced int4, MLX gather buffers) is a
  separate terminal pass.
- Extended int4.py / gguf.py to plug into the shared conversion path.
- Removed the old per-model examples/models/gemma4_31b/quant/ packers
  (pack.py, pack_cuda.py, pack_mlx.py) and moved packing into
  examples/models/gemma4_31b/cuda_packers.py, wiring gemma4_31b and
  qwen3_5_moe onto the shared package.
- Added unit tests for the new package and the gemma4_31b packers/pipelines.

Reviewed By: Gasoonjia

Differential Revision: D112867629
@metascroy
metascroy force-pushed the export-D112867629 branch from 7b40560 to d18198d Compare July 21, 2026 00:43
@metascroy
metascroy merged commit 110ac65 into pytorch:main Jul 21, 2026
288 of 296 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/cuda ciflow/mlx CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants