Fix kernel mapping bug when multiple devices exist (Issue #42451) #42486
+72
−8
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.
Fix kernel mapping bug when multiple devices exist (Issue #42451)
Fixes #42451
Summary
Fixes issue #42451 where
add_to_mapping()would overwrite existing device entries whenkernel_mappingcontained multiplsame layer (e.g., both "cuda" and "rocm").
Problem
When
kernel_mappingcontains multiple devices for the same layer, callingadd_to_mapping()repeatedly would overwrite tentry instead of adding to it. This occurred because the function was completely replacing
compatible_mapping[layer_name]Example of the bug:
Solution
Updated
add_to_mapping()to check iflayer_nameanddeviceentries already exist before overwriting. The function nowlayer_nameentry if it doesn't existdeviceentry if it doesn't existThis ensures all devices are preserved in the
compatible_mappingstructure.Changes
Modified:
src/transformers/utils/kernel_config.pyadd_to_mapping()function to preserve existing device entriesAdded:
tests/kernels/test_kernels.pytest_add_to_mapping_multiple_devices: Verifies multiple devices are preservedtest_add_to_mapping_single_device: Ensures backward compatibilitytest_add_to_mapping_multiple_modes: Verifies multiple modes work correctlyTesting
All tests pass:
test_add_to_mapping_multiple_devices- PASSEDtest_add_to_mapping_multiple_modes- PASSEDtest_add_to_mapping_single_device- PASSEDTestKernelUtilities- PASSEDChecklist