AsyncGRPOTrainer: add model_init_kwargs support#5893
Open
rycerzes wants to merge 1 commit into
Open
Conversation
Add model_init_kwargs to AsyncGRPOConfig and use create_model_from_path in the trainer, matching GRPOTrainer's model loading behavior. This allows passing custom kwargs (e.g., attn_implementation, dtype) when loading the model from a string. Closes part of huggingface#5831
8 tasks
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.
What does this PR do?
Adds
model_init_kwargssupport toAsyncGRPOTrainer, matching the existing behavior inGRPOTrainer.Currently,
AsyncGRPOTrainerhardcodesAutoModelForCausalLM.from_pretrained(model, device_map=None, dtype=torch.float32), which prevents passing custom kwargs likeattn_implementationordtype. This PR:model_init_kwargsfield toAsyncGRPOConfig(with_VALID_DICT_FIELDSfor dict serialization support)AutoModelForCausalLMloading withcreate_model_from_path(model, **model_init_kwargs), which infers the correct architecture class from the model config (important for models like Qwen3.5 that useQwen3_5ForConditionalGenerationinstead of a standard CausalLM)device_map=Nonefor FSDP2 compatibilityChanges:
async_grpo_config.py: addmodel_init_kwargsfield + docstring +_VALID_DICT_FIELDSasync_grpo_trainer.py: replaceAutoModelForCausalLMwithcreate_model_from_path, update importsTests:
test_model_init_kwargs: verifies thatmodel_init_kwargs={"dtype": "bfloat16"}results in bfloat16 model parametersCloses part of #5831
Before submitting
AI writing disclosure
Who can review?
@qgallouedec
Note
Low Risk
Small, localized change to model instantiation with an existing shared helper and a focused unit test; no auth or rollout pipeline logic changes.
Overview
AsyncGRPOTrainercan now take optionalmodel_init_kwargsonAsyncGRPOConfig, aligned withGRPOTrainer, so string model IDs acceptfrom_pretrainedoptions (e.g.dtype,attn_implementation) instead of a fixedAutoModelForCausalLMload withdtype=torch.float32.Loading goes through
create_model_from_path, which picks the architecture from the hub config (not only causal LM).device_map=Noneis always applied for FSDP2. A test assertsbfloat16parameters whenmodel_init_kwargs={"dtype": "bfloat16"}.Reviewed by Cursor Bugbot for commit b925002. Bugbot is set up for automated code reviews on this repo. Configure here.