fix: convert string values to enum types in update_config#1021
Open
Mr-Neutr0n wants to merge 1 commit intometa-llama:mainfrom
Open
fix: convert string values to enum types in update_config#1021Mr-Neutr0n wants to merge 1 commit intometa-llama:mainfrom
Mr-Neutr0n wants to merge 1 commit intometa-llama:mainfrom
Conversation
When passing enum values like sharding_strategy from the command line as strings (e.g., --fsdp_config.sharding_strategy="FULL_SHARD"), the string was not converted to the ShardingStrategy enum, causing a KeyError in PyTorch's FSDP initialization. Added _convert_to_field_type() helper that: 1. Uses get_type_hints() to get the expected field type 2. Converts string values to enum types if the expected type is an Enum This allows users to pass enum values as strings from the command line and have them automatically converted to the correct enum type. Fixes meta-llama#809
Author
|
Friendly bump! Let me know if there's anything I should update or improve to help move this forward. |
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.
Summary
Fix KeyError when passing enum values like
sharding_strategyas strings from the command line.Problem
When running with
--fsdp_config.sharding_strategy "FULL_SHARD", the string value is not converted toShardingStrategyenum, causing:PyTorch's FSDP expects a
ShardingStrategyenum value, not a string.Solution
Added
_convert_to_field_type()helper function that:get_type_hints()to get the expected field type from the dataclassEnumand the value is a string, converts it usingEnumClass[value]This allows users to pass enum values as strings from the command line:
The fix also works for
checkpoint_type(StateDictType enum) and any future enum fields.Fixes #809