Skip to content

fix: handle removal of distributed_operation in Transformers TP rework - #3553

Draft
peft-jambot wants to merge 1 commit into
huggingface:mainfrom
peft-jambot:FIX/transformers-tp-distributed-operation
Draft

fix: handle removal of distributed_operation in Transformers TP rework#3553
peft-jambot wants to merge 1 commit into
huggingface:mainfrom
peft-jambot:FIX/transformers-tp-distributed-operation

Conversation

@peft-jambot

Copy link
Copy Markdown
Contributor

Problem

Transformers PR #47579 reworked tensor parallelism (TP) to use a DTensor-based API, replacing the legacy distributed_operation mechanism. This PR removed the distributed_operation attribute from WeightTransform.__slots__ and __init__ in core_model_loading.py.

PEFT's build_peft_weight_mapping function in src/peft/utils/transformers_weight_conversion.py directly accessed orig_conversion.distributed_operation when building new WeightConverter objects for MoE LoRA adapter conversion (lines 279 and 321). With the new Transformers code, this attribute no longer exists, causing:

AttributeError: 'WeightConverter' object has no attribute 'distributed_operation'

This breaks loading LoRA adapters on MoE models (e.g. Mixtral) when using the new Transformers TP code, as exercised by the Transformers test test_mixtral_lora_conversion.

Solution

Introduced a _copy_runtime_attributes helper that copies optional runtime attributes (distributed_operation and quantization_operation) from the original converter to the new PEFT-specific converter using hasattr/setattr. Attributes that don't exist on the source (like distributed_operation on new Transformers) are silently skipped.

This is backward compatible:

  • Older Transformers (with distributed_operation): The attribute is still copied as before.
  • Newer Transformers (PR #47579, without distributed_operation): The attribute is skipped, and only quantization_operation is copied.

Testing

Ran the following tests with both Transformers main (v5.16.0.dev0, still has distributed_operation) and Transformers PR #47579 branch (v5.15.0.dev0, distributed_operation removed):

pytest tests/test_integrations.py -k "mixtral" -v

All 5 mixtral tests pass on both versions. Also ran the new regression test and the Transformers-side test:

pytest tests/test_integrations.py::TestTransformersV5::test_build_peft_weight_mapping_without_distributed_operation
pytest tests/peft_integration/test_peft_integration.py::PeftIntegrationTester::test_mixtral_lora_conversion

Both pass on both Transformers versions.

Regression test

Added test_build_peft_weight_mapping_without_distributed_operation to tests/test_integrations.py which constructs WeightConverter objects (simulating what get_model_conversion_mapping returns) and verifies build_peft_weight_mapping works regardless of whether distributed_operation exists.

Notes

  • AI assistance was used for this PR.
  • The fix is minimal and does not change any behavior for existing Transformers versions.

Transformers PR #47579 reworked tensor parallelism to use DTensor-based
sharding, removing the distributed_operation attribute from
WeightConverter/WeightTransform. PEFT's build_peft_weight_mapping
directly accessed this attribute when copying runtime attributes from
original converters to PEFT-specific ones, causing an AttributeError
on newer Transformers versions.

Replace the direct attribute access with a helper that uses
hasattr/setattr to copy optional runtime attributes (distributed_operation
and quantization_operation) only when they exist on the source object.
This maintains backward compatibility with older Transformers versions
that still have distributed_operation while working with the new
DTensor-based TP code.
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.

1 participant