torchtune as an optional dependency: Lazy Import
good first issueactionabletriagedtorchtune
### 🚀 The feature, motivation and pitch
We would like to make `torchtune` an optional dependency. The first step towards that is to avoid importing `torchtune` unless it is actively used.
To make this migration easier, let's move the top level imports into the functions/classes that require them.
> We explicitly acknowledge that this initial step isn't a best practice, but will make the following work simpler.
Here's an example where we delay imports here: https://github.com/pytorch/torchchat/blob/1384f7d3d7af0847d8364fe7b300a8b49f2213c2/torchchat/usages/eval.py#L216-L225
**Task:** Update all imports of `torchtune` in the repo, such that imports are only done when necessary
- Suggestion: Feel free to send out PR's that only update a subset of all use cases
To test your changes, run:
- With torchtune installed: https://github.com/pytorch/torchchat/blob/main/docs/multimodal.md#generation
- With torchtune uninstalled: `python torchchat.py generate llama3.2-1B`
### Alternatives
_No response_
### Additional context
_No response_
### RFC (Optional)
_No response_
2 条评论