fix: handle removal of distributed_operation in Transformers TP rework - #3553
Draft
peft-jambot wants to merge 1 commit into
Draft
fix: handle removal of distributed_operation in Transformers TP rework#3553peft-jambot wants to merge 1 commit into
peft-jambot wants to merge 1 commit into
Conversation
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.
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.
Problem
Transformers PR #47579 reworked tensor parallelism (TP) to use a DTensor-based API, replacing the legacy
distributed_operationmechanism. This PR removed thedistributed_operationattribute fromWeightTransform.__slots__and__init__incore_model_loading.py.PEFT's
build_peft_weight_mappingfunction insrc/peft/utils/transformers_weight_conversion.pydirectly accessedorig_conversion.distributed_operationwhen building newWeightConverterobjects for MoE LoRA adapter conversion (lines 279 and 321). With the new Transformers code, this attribute no longer exists, causing: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_attributeshelper that copies optional runtime attributes (distributed_operationandquantization_operation) from the original converter to the new PEFT-specific converter usinghasattr/setattr. Attributes that don't exist on the source (likedistributed_operationon new Transformers) are silently skipped.This is backward compatible:
distributed_operation): The attribute is still copied as before.distributed_operation): The attribute is skipped, and onlyquantization_operationis copied.Testing
Ran the following tests with both Transformers
main(v5.16.0.dev0, still hasdistributed_operation) and Transformers PR #47579 branch (v5.15.0.dev0,distributed_operationremoved):All 5 mixtral tests pass on both versions. Also ran the new regression test and the Transformers-side test:
Both pass on both Transformers versions.
Regression test
Added
test_build_peft_weight_mapping_without_distributed_operationtotests/test_integrations.pywhich constructsWeightConverterobjects (simulating whatget_model_conversion_mappingreturns) and verifiesbuild_peft_weight_mappingworks regardless of whetherdistributed_operationexists.Notes