Commit Graph
304 Commits
Author SHA1 Message Date
Kyle Sayers 455c9a0491 Fix compressed-tensors loading of KV-cache-only checkpoints (#50030)
A compressed-tensors checkpoint that only quantizes the KV cache
(`kv_cache_scheme` set, no `config_groups`) crashed at load time:
`get_experts_scheme` indexed `groups[0]` on an empty list from
`serialized_names` and `get_load_operations`. Guard both on empty
config groups, like the existing sparsity-only case, and add a CI
test on inference-optimization/TinyQwen3-KV-Cache-Only that checks
the scales load onto every attention module.
2026-10-27 15:50:51 +00:00
Ilyas MoutawwakilandClaude Opus 5.5 944e22eb22 Match a skip-list entry from the start only up to a module boundary (#49771)
* Match a skip-list entry from the start only up to a module boundary

should_convert_module matched an entry from the start of the module name with
no boundary after it, so "model.layers.1" also skipped model.layers.10 to 19,
and Qwen3.8-27B-FP8's router entry "mlp.gate" also skipped the quantized
mlp.gate_proj (its FP8 weight then reached a bf16 linear). A match from the
start now has to end on a "." it consumed, or right before a "." or the end
of the name, which keeps regex entries that carry their own boundary such as
"^model\.audio_tower(?:\.|$)". The endswith clause Hub skip-lists rely on
("gate" covering shared_expert_gate) is unchanged.

Supersedes #47990, which anchors with "$" and so stops matching such regex
entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Shorten the should_convert_module docstring

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Restore the matching-rules comment of should_convert_module

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Move the should_convert_module test to a general quantizer utils test file

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Explain why the skip-list key is grouped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Fit the skip-list comment within the noisy-comment limits

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Name the skip-list test's exclusion lists modules_to_not_convert

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 13:22:36 +00:00
eb943c26b9 Fix DeepGEMM Mega MoE under expert parallelism (#49428)
Since DeepSeek-V4 declares `ep_dispatch_experts`, the Mega MoE override left that rule in place: token dispatch
wrapped the Mega MoE experts and called them without a process group, so `tp_size=ep_size` runs raised on the first
forward. The older `ep_router` + `moe_tp_experts` plan was never applied either, since the override renamed both
styles and the mixin matched neither.

Mega MoE dispatches inside its kernel, so it takes over the experts rule (`ep_dispatch_experts` ->
`megamoe_experts`), runs on the TP group like masked EP, and requires `ep_size == tp_size`.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Anton Vlasjuk <73884904+vasqu@users.noreply.github.com>
2026-10-16 13:27:41 +02:00
Arthur b7c4168479 Quantization cleanpup (#49548)
* first cleanup

* more cleanup

The various agent PRs most probably did not understand the core logic /
idea behind the weight converter, this left a lot of method patching
here and ther.
1. Deserialize: some method just need a cast, other need more work. The
ConversionOps added as the "first" operation, updating the weights
conversion (each one of them) are here for that.
2. TP: bloated code to just update a plan.
3. Patch: I have no idea how, but we accepted plans that had explicit
overwrite. This is legacy

* update

* sub config fixes

Saw another PR recently: #48759, had the same bug. this adresses it

* more simplification

* debloat more shit, standardize

* nits

* fucking bloatland

* Fix PR slow CI suggestion install: non-editable install

* update now that the $ bloat is gone

* Fix PR slow CI suggestion: install transformers in a venv (system site-packages not writable)

* metal tests: unanchored weight key

* nits this time

* up

* remove last pieces of dead code

* fix failing test

* fix test

* pr comments

* human coments

* Treat scales and etc individually?

* use a map

* replicate explicitely

* impl copy

* Quantized element size as property, one-line FP8Experts comments, ue8m0 float32 scale loading test

* Drop the $ anchor from the bailing_hybrid expert_bias renaming, patterns end on a name boundary now

* Restore the 1 byte quantized element size of FineGrainedFP8

* Quantized element size as a property in every quantizer
2026-10-16 11:38:59 +02:00
Wang, Yi 9fb4b5a945 Aligns test expectations with the accelerator path under test: (#49653)
- Expects the same greenlist token in the watermark test on XPU and other devices.
- Uses the multi-accelerator requirement for GPTQ device-map tests instead of a multi-GPU-only requirement.
- Runs the MXFP4 low CUDA compute-capability tests only on CUDA, since their mocked CUDA capability is not read on XPU.

Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>
2026-10-16 06:11:55 +00:00
Franci Penov 680a17f4e9 Add LFM2 to the GGUF loading path (#49400)
* Add LFM2 to the GGUF loading path

* Add a standalone LFM2 GGUF tokenizer test
2026-10-14 15:55:31 +00:00
Marc Sun 8a5a4b5c02 gguf user defined tokens (#49008)
* GGUF tokenizer: keep the file's user-defined tokens whole

A GGUF marks tokens like `<think>`, `</think>`, `<tool_call>` and `<tool_response>` as
USER_DEFINED. llama.cpp always matches these whole in the text, and the reference tokenizers
carry them as non-special added tokens. The GGUF-built tokenizer only registered CONTROL
tokens, so `<think>` was cut into `<`, `think`, `>`: every chat prompt for Qwen3.5 differed
from what llama.cpp feeds the model. Add them as plain added tokens, restricted to spellings
already in the vocabulary so a sentencepiece file's raw whitespace runs do not grow it.

* update comment
2026-09-30 13:33:29 +00:00
Marc Sun 235efe71bd Update ggml kernels path (#48991)
move to ggml-org
2026-09-22 10:07:45 +00:00
Marc Sun f7ca943f69 Update tokenizer gguf support (#48656)
* better support tokenizer

* fix

* fix

* better now !

* better doc

* update !

* slow

* style

* style

* Trigger CI

* cleannnn

* remove some comments
2026-09-22 09:28:28 +00:00
Marc SunandPedro Cuenca abd76d121e Better attn default for gguf (#48935)
* better default

* up

* Apply batched suggestions from code review

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>

---------

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
2026-09-21 12:19:47 +00:00
Marc Sun 41f519e741 Qwen3.8 GGUF (#48660)
* more support

* more dequant ops

* optimize dequant
2026-09-15 20:23:44 +00:00
Marc Sun 26d8e7164f Support for MoE in the GGUF integration (#48529)
* support Qwen3.5-MoE GGUF files

Adds the `qwen35moe` architecture to the config, conversion and tokenizer mappings, the expert-bank
tensors to the loading path, and grafts the router and zero-centred norm kernels onto the model. The
layers are named `SoftmaxTopKRouter` and `RMSNormZeroCentered` rather than `TopKRouter`/`RMSNorm`: a
kernel for the plain names would reorder softmax and top-k, exact only for a softmax router, and
would compute `x * w` where this norm needs `x * (1 + w)`.

* clean

* cleaned

* better !

* update kernels

* up

* update
2026-09-15 17:54:40 +00:00
Tarek Ziade 8fcb52399c QA: Added a MemoryCleanupMixin class for tests (#48681)
* initial draft

* Address serge review: audit the no-grad default and pin the private hook

* You are such a verbose agent.

* Review round from @ydshieh, @vasqu and @stevhliu

* vasqu round 2: docs cross-reference, a note block, a class name, and test_kernels

* @ydshieh round 2: rename the grad knob, name the numbers, explain the rest
2026-09-11 09:16:28 +00:00
Marc Sun f62dc9bf2c Refactor GGUF to speed-up inference (#47779)
* gguf non quantized

* add support for q_k

* kernels and config

* better integration with kernels

* small update

* fix

* fix

* support for ggml-attn

* update

* fix

* update

* fix

* kernels gated delta

* Revert "kernels gated delta"

This reverts commit b963ea10e5.

* kernels gated delta agin

* input permutation

* style

* update integration

* up

* docs and bunch of fixes

* tokenizer for qwen3.5

* fix ci and doc

* cleaner integration

* up

* fix

* update

* fix

* up

* serve fix

* doc

* leftover stuff

* minor fix

* norm ! 11% speed increase

* up

* correct path !

* update

* less verbose
2026-09-04 14:54:30 +00:00
JJJYmmm 26865212c4 fix qwen4exp-fp8 ple embedding (#48368)
* fix qwen4exp-fp8 ple embedding

* fix weight_scale resave

* add modules_to_convert

* unnecessary dtype

* lets use super

* automatically anchor weight targets
2026-09-01 08:49:37 +00:00
Tarek ZiadeandClaude Opus 5 275b5245f5 Fix gpt_oss runs on GPU (#48118)
* tweak the kernels dep

* Skip gpt_oss kernels-dependent tests without kernels

* OOM guards

* Make the CPU-RAM probe container-aware and guard host RAM in gpt-oss

`psutil.virtual_memory().total` reads the host `/proc/meminfo`, so inside a K8S pod it reports the
whole node (~750 GiB) and says nothing about the cgroup limit the OOM killer enforces. The
`CI_CPU_MEMORY_LIMIT_GB` patch in `conftest.py` only half-covers this: it deliberately caps psutil at
`limit * num_accelerators` (a `device_map="auto"` planning budget), which is 120 GiB on a 2-GPU runner
whose cgroup still kills at 60.

- add `get_cgroup_memory_limit_bytes()` (cgroup v2 `memory.max`, v1 `memory.limit_in_bytes`, with
  their respective unlimited sentinels)
- add `get_cpu_ram_total_gib()`, taking the min of the cgroup limit, psutil, and the raw
  `CI_CPU_MEMORY_LIMIT_GB`
- rebuild `require_large_cpu_ram` on it, and accept `@require_large_cpu_ram(memory=N)` as well as the
  bare form, matching `require_torch_large_accelerator`. This also fixes its two existing users
  (gemma2, longcat_flash), which were subject to the same host-vs-pod bug.
- guard `test_model_outputs_distributed` on host RAM too: `distributed_worker` loads with no
  `device_map` and moves the model afterwards, so the whole checkpoint transits host RAM first --
  that is the allocation that got the CI container SIGKILLed.

Also cite the exact weight footprints from `modeling_utils.get_total_byte_count` on a meta-device
model (38.96 GiB for 20b, 217.61 GiB for 120b) so the budgets are traceable rather than guessed.

* Address review: separate the measured CPU RAM limit from the CI budget

Follow-up to @ydshieh's review on #48118.

`get_cpu_ram_total_gib` took the min of three values, one of which was `CI_CPU_MEMORY_LIMIT_GB` read raw. That
variable is a *per-accelerator* budget, so on a 2-accelerator A10 runner it reads 60 GiB where the runner really
has 180 -- every guard on that runner would over-skip. Multiplying by the accelerator count (what `conftest.py`
already does when patching psutil) gets to 120, still not 180, because the budget is an allocation policy for
`device_map="auto"` rather than a measurement of the machine.

So split the two apart:

- prefer what can be measured -- the cgroup limit the OOM killer enforces, and the machine's physical RAM --
  taking the smaller, since each is wrong on its own (no cgroup outside a container; physical RAM reports the
  whole node inside a pod)
- fall back to the CI budget only when neither can answer, i.e. on an instance-sharing runner with no cgroup
  limit of its own
- add `get_ci_cpu_memory_budget_gib` as the single source of truth for the per-accelerator arithmetic, and have
  `conftest.py` use it instead of its own inline copy
- add `get_physical_cpu_ram_gib`, which reads past the `patch_psutil_cpu_memory` cap. Without this the fallback
  above is unreachable in CI: conftest patches psutil at session start, so "physical RAM" would report the
  planning budget back to us rather than the machine.

Return `inf` rather than 0 when nothing can answer at all -- no cgroup, no psutil, no CI budget. That is an
ordinary local setup, not a broken one, and 0 silently skipped every memory-guarded test. `require_large_cpu_ram`
loses its `is_psutil_available` early-return, now redundant; this also closes a gap where a container *without*
psutil ran the test blind instead of consulting its cgroup limit.

Also note in the docstrings that the 80 GiB default is "more than our 60 GiB GPU runners" rather than an estimate
of any model, and that ROCm reaches `get_accelerator_total_memory_gib` through the cuda branch (a HIP build
reports `torch_device == "cuda"`), since the existing comment read as though it were excluded.

Tests cover the resolution order in all four environments, including that the guard reads past the psutil cap.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-21 13:35:12 +00:00
Ferdinand MomandArthur 861f4c41ee 🚨 TP dtensor API inference + training (#47579)
* add distributed config

* Add native FSDP2 module and migrate FSDP imports (Phase A PR-2).

Move FSDP2 wrapping and plan verification to distributed/fsdp.py, keep
integrations/fsdp.py as a backward-compatible re-export, and update core
call sites to import from transformers.distributed.fsdp.

* linting

* unecessary

* copyright edit

* revert

* add shard on read

* jsut shard on read

* cleaning

* linting

* fix

* fix

* remove redundant test file

* Update src/transformers/distributed/fsdp.py

naming

Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>

* avoid looping, just look at dict

* expand_fsdp returns reshard_targets, no_reshard_targets right away

* better _resolve_tied_embed_lm_head_plan

* cleaning

* ruff

* more robust detection of embed and lm_head

* cleaning

* ruff

* typo

* cleaner

* cleaner

* typo

* refactor dense path + apply_contiguous_shard

* linting

* cleaning

* refactor _apply_strided_shard

* better

* refactor _slice_and_cat

* better comment

* refactor moe dtensor shard ops

* better comment

* comment

* cleaning

* linting

* Add FSDP orchestration: mesh init, distribute-before-load, and DCP save.

Wire distributed_config from_pretrained/save_pretrained alongside the legacy tp_plan path, add distributed/utils.py for mesh orchestration and checkpoint I/O, and extend sharding_utils with DTensor gather/optimizer fusion helpers needed by save/load.

* add fsdp plan to 2 models for now

* add tests fsdp mixin

* linting

* refactor test fsdp mixin

* test fsdp mixin cleaning

* remove fsdp policy in tests + trim down further

* test fsdp clean

* restore test_modeling_utils

* linting

* start trim down stuff

* fix

* breaking: cleaning modeling_utils.py

* load path with fsdp (dtensor) and tp (old tp) is linked

* linting

* add saving

* styling

* fix tp ci

* add fsdp to ci

* linting

* pick one model only for this PR

* restore

* trigger fsdp ci

* doc cleaning +  tp_size remove

* fix tp ci for ep

* edit doc

* move distributed function to utils + guarding

* linting

* expand_fsdp_plan iterate over modules

* comment about tie embedding

* add comment tied embedding

* add DistributedMixin

* some cleaning

* cleaning + comment

* rename function for clarity

* Apply suggestion from @ArthurZucker

Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>

* doc

* comment

* linting

* refactor

* abstract to mixin

* typo

* Add FSDP plans to all models from distributed branch.

Port base_model_fsdp_plan and ForCausalLM _fsdp_plan entries from PR #46269
and expand FSDP distributed test coverage to the pilot model subset.

* fsdp plans

* linting

* linting

* Add distributed runtime utils and DistributedMixin (FSDP orchestration 1/3).

Introduce distributed/utils.py and DistributedMixin, defer DistributedConfig
validation to load time, and refactor PreTrainedModel plan properties without
changing the from_pretrained distributed_config API yet.

* Wire DistributedConfig through from_pretrained and save_pretrained (FSDP orchestration 2/3).

Route distributed loading and saving through DistributedMixin, migrate TP tests
and docs off tp_plan="auto", and add FSDP gather/DCP save paths.

* Add FSDP CI and end-to-end FSDP tests (FSDP orchestration 3/3).

Add FSDPTesterMixin, cohere2_moe base_fsdp_plan, dedicated fsdp_ci job, and
pytest markers for distributed FSDP load/save/generation coverage.

* addd ep_plan

* restore validate module

* Wire DistributedConfig through from_pretrained and save_pretrained.

Route distributed load/save orchestration through DistributedMixin so TP and FSDP paths share the same entry points.

* revert

* inline distribute_model

* revert

* remove saving/loading

* leaner mixin

* downgrade torch version guarding

* remove

* linting

* revert

* revert

* post_init() parallel plan move to mixin

* revert tp mixin

* add save/load

* only FSDP save/load for now

* revert

* refactor

* modular

* ea

* begin migration TP

* clean up

* add it to pretrained model

* linting

* fix the test by moving in init class the fsdp plan instead of post init

* edit

* replace everything

* begin migration TP

* clean up

* revert merge conflict

* local params for forward

* cleaning

* migration from integration.tensor_parallel to   distributed.tensor_parallel

* revert models

* revert

* fix

* breaking: cleaner way to_local for quantize weight(almost done need to fix backward)

* fix all tests

* TP dtensor handle natively the to_local() for deepgem + fp8 (#47634)

* Refactor distributed tensor_parallel module and TP mixin tests

* better approach to to_local

* pass as class method

* cleaning PackedColwise

* remove the use of to_local in kernels to offload this task to TensorParallel

* rowwise bias after redistribute

* make it easier to understand

* requires grad only for floating point numbers

* fix tp meagamoe fp8 with dtensor

* linting

* revert gitignore

* fix run slow quantization ci

* fix deepseek v4 ep backward tests

* fix deepseek glm4 moe tp backward pass

* Refactor tensor parallel loading logic by removing unused tp_plan handling and updating is_dtensor type hint for better type safety.

* linting

* bench: dtensor vs legacy TP

* bench: dtensor vs legacy TP (#47728)

* bench: dtensor vs legacy TP

* clean rowise

* refactor colwise

* comment

* comment

* refactor MoEExperParallel

* ruff

* add rowwise input

* remove helper script

* remove dead code in mxfp4

* remove old TP

* cleaning

* cleaning

* claening

* add test_shard_tensor_shape_consistency

* cleaning

* small fix

* typo

* comment

* rename colwise_gather_output to colwise_rep

* keep tp import to avoid breaking chnges

* remove async_op=True for redistribute

* linting

* renaming MoeExpertsParallel class

* ep router doc

* mlinter

* add todo

* fix

* remove unused keys from global_mapping to avoid BC

---------

Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
2026-08-21 12:25:37 +00:00
80c667443d feat: add nvfp4 quantization (#47883)
* feat: add nvfp4 quantization

Signed-off-by: David Holtz <david.richard.holtz@gmail.com>

* Update docs/source/en/quantization/nvfp4.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/quantization/nvfp4.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* docs: point nvfp4 overview link at kernels-community

* fix: remove unused global and unittest call

---------

Signed-off-by: David Holtz <david.richard.holtz@gmail.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
Co-authored-by: Cyril Vallez <cyril.vallez@huggingface.co>
2026-08-18 15:05:02 +00:00
Yi LiuandSteven Liu 8cea475157 Update AutoRound XPU/CPU backend (#47826)
* fix: update AutoRound backend docs to ARK

* update

Signed-off-by: yiliu30 <yi4.liu@intel.com>

* Update docs/source/en/quantization/auto_round.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/quantization/auto_round.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update src/transformers/utils/quantization_config.py

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

---------

Signed-off-by: yiliu30 <yi4.liu@intel.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
2026-08-10 16:18:11 +00:00
Vasiliy KuznetsovandClaude Opus 4.8 0c98a994d3 Migrate torchao integration off deleted torchao.dtypes (#47797)
torchao removed the torchao/dtypes package (AffineQuantizedTensor and the
Layout classes). This updates the transformers torchao integration to stop
importing from torchao.dtypes so it no longer crashes against current
torchao, mirroring the approach in transformers #45321.

Changes:
- integrations/torchao.py: drop the `_quantization_type` helper and its
  `from torchao.dtypes import AffineQuantizedTensor` isinstance branch;
  `_linear_extra_repr` now detects quantized weights inline via
  `isinstance(self.weight, TorchAOBaseTensor)` (from torchao.utils).
- tests/quantization/torchao_integration/test_torchao.py: replace the
  `from torchao.dtypes import AffineQuantizedTensor` import with
  `from torchao.utils import TorchAOBaseTensor` and update the isinstance
  assertions accordingly.
- docs/source/en/quantization/torchao.md: remove the MarlinSparseLayout
  ("int4-weight-only-24sparse") examples and migrate the Int4CPULayout
  example to `Int4WeightOnlyConfig(int4_packing_format=PLAIN_INT32)`.

Test plan:
- `python -c "import transformers.integrations.torchao"` imports cleanly.
- `RUN_SLOW=1 pytest tests/quantization/torchao_integration/test_torchao.py`:
  all 18 TorchAOBaseTensor isinstance / FqnToConfig tests pass. The 3
  remaining failures (test_int4wo_quant, test_int4wo_offload,
  test_serialization_accelerator_*_Int4WeightOnlyConfig) are pre-existing
  generation-output text comparisons pinned to torchao int4 kernel numerics
  on the test hardware, unrelated to this change.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-05 13:52:35 +00:00
Marc Sun 20c8db788a Fix compressed tensors impl (#47652)
* fix compressed tensors

* update
2026-07-31 15:18:58 +00:00
Wang, YiandIlyas Moutawwakil 67554d9a59 extend tests/quantization/gptq/test_gptq.py::GPTQTestCUDA and tests/q… (#47166)
* extend tests/quantization/gptq/test_gptq.py::GPTQTestCUDA and tests/quantization/mxfp4/test_mxfp4.py::Mxfp4QuantizerTest to xpu

Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>

* update

Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>

* update

Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>

* enable cpu fpr gptq test

Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>

---------

Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>
Co-authored-by: Ilyas Moutawwakil <57442720+IlyasMoutawwakil@users.noreply.github.com>
2026-07-30 15:13:26 +00:00
23bcc79011 Compressed tensors fp8 (#47216)
* add compressed-tensor fp8 integeration

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* update

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* update

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* update copyright

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* rm fbgemm kernel from compressed tensor

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix format

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* rm fbgemm rely

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix format

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix import

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix comments

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix contiguous

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* update doc and tests

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* update

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* Update docs/source/en/quantization/compressed_tensors.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/quantization/compressed_tensors.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/quantization/compressed_tensors.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/quantization/compressed_tensors.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/quantization/compressed_tensors.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/quantization/compressed_tensors.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/quantization/compressed_tensors.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* update doc

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* Update docs/source/en/quantization/compressed_tensors.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* fix comments

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix format

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix fp8 check

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* update

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* update

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* rm unrelated change

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* update

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix name

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix static

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix format

* update integration

* update

* update

* fix

* fix

* fix

---------

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
Co-authored-by: jiqing-feng <jiqing.feng@intel.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
2026-07-29 13:17:01 +00:00
c0142e6f75 [Quantization]: Refactor is_quantization_compressed for format-based detection (#47152)
* [Quantization]: Refactor is_quantization_compressed for format-based detection

* Add regression test for FP8 frozen compressed-tensors models

Co-authored-by: subin9 <101092510+subin9@users.noreply.github.com>

---------

Co-authored-by: subin9 <101092510+subin9@users.noreply.github.com>
Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>
2026-07-22 15:38:45 +00:00
Ilyas Moutawwakil 01b03b2e9f Fix deepgemm on multiple devices (#47323)
* claude's fix

* fix multi device deepgemm

* address comments

* added test

* deprecate following torch linear

* remove from docstring

* address comments
2026-07-16 11:26:39 +02:00
jiqing-feng 22d9409110 Fix BitNet packed-weight unpacking dtype (F.linear dtype mismatch) (#46808)
* fix bitnet dtype

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* add test

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

---------

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
2026-06-24 13:24:00 +00:00
a921b4d886 Quantization for small models (#46449)
* Quantization for small models

Co-authored-by: Marc Sun <marc.sun@hotmail.fr>
Co-authored-by: Phil Culliton <phillipculliton@gmail.com>
Co-authored-by: Ryan Mullins <ryan@ryanmullins.org>

* fix CI

* let's ignore for now

* ignore docs for now, later todo

---------

Co-authored-by: Marc Sun <marc.sun@hotmail.fr>
Co-authored-by: Phil Culliton <phillipculliton@gmail.com>
Co-authored-by: Ryan Mullins <ryan@ryanmullins.org>
Co-authored-by: vasqu <antonprogamer@gmail.com>
2026-06-05 17:40:59 +02:00
jiqing-feng b9d2bb4a44 skip deepgemm test except cuda (#46090)
skip deepgemm test for xpu

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
2026-06-05 13:50:04 +00:00
Marc SunandLinZiyuu 4ae05b0fba Update compressed tensors minimum version (#46342)
* update compressed-tensors support

* Add LinZiyuu as co-author

Co-authored-by: LinZiyuu <104151270+LinZiyuu@users.noreply.github.com>

* md

* style

---------

Co-authored-by: LinZiyuu <104151270+LinZiyuu@users.noreply.github.com>
2026-06-02 14:56:31 +00:00
jiqing-feng f4c5ae11c7 Fix torchao behavior for xpu (#46096)
* fix xpu torchao int4wo tests

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix int4wo groundtruth

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix ground truth

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix device

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix device checkj

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

---------

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
2026-05-20 06:37:31 +00:00
Marc Sun e651c68e69 Update quants tests (#45480)
* update

* Use torch.testing.assert_close in compressed_tensors weight check
2026-04-27 12:54:21 +00:00
Vasiliy KuznetsovandMarc Sun 03238980c9 fix transformers + torchao nvfp4 serialization (#45573)
Summary:

1. fix torchao NVFP4 serialization with transformers
2. add a test to cover the fix

While i'm here, also did the following bundled into this PR:
3. make the torchao serialization test have human readable names (easier
   to debug)
4. fix the float8 test (update the expected output)

after this PR the test command for all torchao configs passes on an
NVIDIA B200

Test Plan:

```
RUN_SLOW=1 pytest tests/quantization/torchao_integration/test_torchao.py -k "Serialization" -s
```

Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>
2026-04-23 12:22:14 +00:00
Kartik Gupta 5e23868450 Add full GGUF loading support for GPT‑OSS (fixes #43366, supersedes #43757) latest (#45506)
* Add GPT-OSS GGUF support with YaRN rope scaling reconstruction

* Add GGUF loading test suite for GPT‑OSS

* docs: add GGUF loading section to gpt_oss.md

* fix: correct import of GptOssTensorProcessor in test; remove from model __all__

* Finalize GPT‑OSS GGUF support: move test, adjust config reconstruction

* fixed docs not closing example bracket

* Fix lint: remove trailing whitespace

* Fix tensor construction consistency

* reverting to original docs
2026-04-22 06:37:30 +00:00
Ilyas MoutawwakilandAnton Vlasjuk bc576731d4 DeepGEMM (#44832)
* deep gemm

* standardize

* clear deepgemm flow and blackwell optimization

* avoid unnecessary gathers in grouped mm

* assertions and drop the synced path

* use lazy load kernel

* style

* add prefix and check for cuda runtime version

* better names

* exit on missing functions

* comment about why we use deepspeed cutlass single gemm

* global statements

* add cuda check

* fix deepgemm fastpath for models with bf16 scales

* force fp32 scales in experts as well

* Update src/transformers/integrations/finegrained_fp8.py

Co-authored-by: Anton Vlasjuk <73884904+vasqu@users.noreply.github.com>

* Update src/transformers/integrations/hub_kernels.py

Co-authored-by: Anton Vlasjuk <73884904+vasqu@users.noreply.github.com>

* fix

* style

---------

Co-authored-by: Anton Vlasjuk <73884904+vasqu@users.noreply.github.com>
2026-03-31 17:04:02 +02:00
Javier De Jesus 82106705eb fix: split MXFP4 dependency checks for specific error messages (#44930)
* fix: split MXFP4 dependency checks for specific error messages

Fixes #44912. The combined `kernels_available` check made it impossible
to identify which dependency (Triton vs kernels) was missing. Now each
check has its own actionable message with install instructions, following
the established pattern in quantizer_higgs.py.

Also hardens is_triton_available() and is_kernels_available() against
"N/A" version strings from _is_package_available().

* address review: revert import_utils.py changes, reduce tests to 2
2026-03-24 15:17:30 +00:00
Cyril Vallez 7805ec28c1 [generate] Never use cache_position anymore in generation (#44816)
* remove from generation

* update tests

* more tests

* fix

* doc

* last changes

* aqlm slipped through

* add bc for remote code models

* anton's review

* add warning
2026-03-19 15:18:26 +01:00
Marc Sun bfe00b41eb Bump torchao >=0.15 and fix quantization CI (#44604)
* Fix

* update expected

* fix fp_quant

* fix metal

* fix mxfp4

* fix

* fix bnb

* style

* bump torchao to 0.15.0 min to have safetensor support by default

* style

* fix torchao tests

* Fix !

* style

* update docs

* update dockerfile

* build quant docker

* maybe this ?

* uncomment
2026-03-16 16:01:38 +00:00
jiqing-feng f2f7c89413 Fix AWQ tests for GPTQModel migration (#44654)
* fix awq tests

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* update ground truth

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix return replace_with_awq_linear

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* update linear type

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix save and load

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix format

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

---------

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
2026-03-13 16:20:59 +00:00
ff2ba441a8 [Performance] FP8 Grouped and Batched Matmuls (#44231)
* simplify

* finegrained fp8 moe forwards

* optimized fp8 fused, batched and grouped paths

* fix

* wrap triton

* fix calls

* fix

* remove fused quant kernel (litlle gain and unnecessary) and use torch library wrappers for better torch compileability

* use kernels

* fix

* no need to wrap cutlass

* cleanup

* fix

* added non gated experts support

* remove comments

* style

* fix

* Update src/transformers/quantizers/quantizer_finegrained_fp8.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update finegrained_fp8.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* per tensor scaling support

* use custom fp8 interface

* document

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>
2026-03-11 09:51:00 +01:00
Tarek Ziade 42ff4f324f Fix: AQLM quantizer to match updated replace_with_aqlm_linear signature (#44577)
fix AQML argument
2026-03-10 17:36:04 +00:00
Mohamed MekkouriandMarc Sun fc8a657716 [Quantization] Fixing mxfp4 saving using reverse_op (#43148)
* fix

* fix

* style

* update

* fix

* add kernels to docker

* fix

* fix

* revert docker changes

* fix

---------

Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>
2026-02-27 14:28:51 +01:00
Mohamed MekkouriandMarc Sun 9dd90763cd [Quantization] Add metal quantization for MPS devices! (#43934)
* first commit

* style

* fix

* fix

* mlx -> metal

* other fixes

* add tests

* fixes

* weight -> qweight

* fix

* tests

* fix style

* fix

* toctree

* some docs

* qweight -> weight

* fix dtype

* rm print

* overview

---------

Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>
2026-02-27 14:28:29 +01:00
jiqing-fengandMohamed Mekkouri 69fd225a38 Enable mxfp4 model on CPU (#43512)
* enable mxfp4 on CPU

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* test mxfp4

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* revert error change

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix mxfp4 device check

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* fix mxfp4 check

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* update tests

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* add cpu dispatch

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* update mxfp4 kernel check

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* dequantize mxfp4 model if don't use kernels on CPU

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

* rm comments

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>

---------

Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
Co-authored-by: Mohamed Mekkouri <93391238+MekkCyber@users.noreply.github.com>
2026-02-24 16:22:00 +01:00
49067bc9dd Add Four Over Six quantization integration (#43970)
* Add fouroversix integration and docs

* Small fix

* Update quantized modules outside of FourOverSixQuantize

* Delete high-precision parameters during conversion and before weight loading

* Update year

Co-authored-by: Mohamed Mekkouri <93391238+MekkCyber@users.noreply.github.com>

* Replace FourOverSixLinear check with QuantizedModule check

* Run fix-repo

* Update fouroversix

* Update check_docstrings

* Fix keep_master_weights

* Update get_quantized_parameters API

* Apply repo consistency fixes

* Check whether each parameter in a module should be quantized

* Update FourOverSixConfig

* Fix docstring

---------

Co-authored-by: Mohamed Mekkouri <93391238+MekkCyber@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>
2026-02-24 15:29:49 +01:00
Harshal JanjaniandMohamed Mekkouri 08c4ad95d4 fix(models): Unpack BitNet packed weights to fix CI failure (#43721)
* fix: Unpack packed weights in quantizer post-loading hook (AutoBitLinear)

* nit: Fix ci/circleci: check_code_quality

* fix: Simply unpack BitNet weights during loading itself

* fix: Address comments

* review: Add tests

* nit: Change the import

---------

Co-authored-by: Mohamed Mekkouri <93391238+MekkCyber@users.noreply.github.com>
2026-02-16 15:38:18 +00:00
53f8a08290 SINQ quantization strategy integration (adapted for Transformers V5) (#43112)
* sinq integration files

* sinq integration update

* sinq integration no lazy import

* Tests for sinq integration

* minor changes to sinq integration

* sinq integration documentation added

* small correction to sinq documentation

* small correction to sinq documentation

* remove auto_patch_io flag and fix the selection of the device for sinq integration

* remove auto_patch_io flag and fix the selection of the device for sinq integration

* remove auto_patch_io flag and fix the selection of the device for sinq integration

* remove auto_patch_io flag and fix the selection of the device for sinq integration

* Code style fix sinq integration

* minor changes in comments for sinq integration

* add for documentation sinq integration

* add documentation for sinq integration

* minor adjustment in sinq quantizer

* minor changes to sinq integration

* delete debugging print in sinq integration

* sinq integration files

* sinq integration update

* sinq integration no lazy import

* Tests for sinq integration

* minor changes to sinq integration

* sinq integration documentation added

* small correction to sinq documentation

* small correction to sinq documentation

* remove auto_patch_io flag and fix the selection of the device for sinq integration

* remove auto_patch_io flag and fix the selection of the device for sinq integration

* remove auto_patch_io flag and fix the selection of the device for sinq integration

* remove auto_patch_io flag and fix the selection of the device for sinq integration

* Code style fix sinq integration

* minor changes in comments for sinq integration

* add for documentation sinq integration

* add documentation for sinq integration

* minor adjustment in sinq quantizer

* minor changes to sinq integration

* delete debugging print in sinq integration

* Adapt sinq integration to transformers v5

* sinq integration for transformers v5

* Added part of the suggested modifications to make the code simpler

* Modification of the quantization flow and remove of asinq option

* Minor adjustments and creation of fuction to substitute quantized layers

* Eliminate device specification in SinqConfig and tests script adaptation

* final adjustments and checks

* final checks

* Fix merge conflict in import_utils

* Fix code quality

* update tests and fixing minor typos

* Fix grammar of warning message

* Update tests/quantization/sinq/test_sinq.py

* Apply repo consistency fixes

---------

Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>
Co-authored-by: Mohamed Mekkouri <93391238+MekkCyber@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-16 16:08:42 +01:00
6d86e9a318 fix fbgemm fp8 multi-device load failure. (#43581)
Signed-off-by: Wang, Yi <yi.a.wang@intel.com>
Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>
Co-authored-by: Mohamed Mekkouri <93391238+MekkCyber@users.noreply.github.com>
2026-02-10 15:51:48 +01:00
b33235e3c0 fix the error of tests/quantization/fbgemm_fp8/test_fbgemm_fp8.py::Fb… (#43547)
fix the error of tests/quantization/fbgemm_fp8/test_fbgemm_fp8.py::FbgemmFp8Test::test_change_loading_attributes

Signed-off-by: Wang, Yi <yi.a.wang@intel.com>
Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>
Co-authored-by: Mohamed Mekkouri <93391238+MekkCyber@users.noreply.github.com>
2026-02-10 14:36:35 +00:00
Yao MatrixandMarc Sun 683c3e9f3e remove ipex and ccl for xpu and cpu (#42852)
* remove ipex and ccl for xpu and cpu, since all ipex optimizations are
upstreamed to PyTorch or kernels-community; ccl for xpu is upstreamed to
PyTorch built-in xccl backend; ccl for cpu will use gloo

Signed-off-by: Yao, Matrix <matrix.yao@intel.com>

* fix style

Signed-off-by: Yao, Matrix <matrix.yao@intel.com>

* xx

Signed-off-by: Yao, Matrix <matrix.yao@intel.com>

* xx

Signed-off-by: Yao, Matrix <matrix.yao@intel.com>

* xx

Signed-off-by: Yao, Matrix <matrix.yao@intel.com>

* xx

Signed-off-by: Yao, Matrix <matrix.yao@intel.com>

* auto-round

Signed-off-by: Matrix YAO <matrix.yao@intel.com>

* xx

Signed-off-by: Matrix YAO <matrix.yao@intel.com>

* fix style

Signed-off-by: Matrix YAO <matrix.yao@intel.com>

* xx

Signed-off-by: Matrix YAO <matrix.yao@intel.com>

* xx

Signed-off-by: Matrix YAO <matrix.yao@intel.com>

---------

Signed-off-by: Yao, Matrix <matrix.yao@intel.com>
Signed-off-by: Matrix YAO <matrix.yao@intel.com>
Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>
2026-02-03 10:40:29 +01:00
Vasiliy KuznetsovandArthur 5772c7333f remove torchao.autoquant from transformers (#43561)
Summary:

This is being deprecated: https://github.com/huggingface/diffusers/pull/13048

Test Plan:

```python
RUN_SLOW=1 pytest tests/quantization/torchao_integration/test_torchao.py -s
```

Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
2026-02-02 12:07:10 +01:00