Make RecipeModel subclasses public #1389
Closed
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.
This PR:
(1) Makes
StandardRecipeModel,DDPModel,FSDP1Model, andFSDP2Modelsubclasses ofRecipeModelpublic.(2) Replaces
RecipeModel.familywhich was of typeModelFamilywithRecipeModel.family_namewhich is of typestr. This makes it a lot easier to use fairseq2Trainer,Evaluator, andValidatorclasses with arbitrary PyTorch modules without having to define a corresponding family.(3) Exposes "as" methods in
RecipeModel,RecipeDataset, andRecipeTokenizeras helpers to safely cast assets to their actual type during runtime.Important Note: This PR introduces a potential BC breaking change in that it replaces
RecipeModel.familywithRecipeModel.family_nameto decoupleRecipeModelandModelFamilytypes. SinceRecipeModel.familyhas been an advanced API released in v0.5, it is likely not used broadly. As long as we can guarantee that no internal repo breaks due to this change, I am okay with merging it by clearly documentingRecipeModelas experimental. If anyone has concerns, please let me know.