Skip to content

torchtune as an optional dependency: Lazy Import #1519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Jack-Khuu opened this issue Mar 31, 2025 · 0 comments
Open

torchtune as an optional dependency: Lazy Import #1519

Jack-Khuu opened this issue Mar 31, 2025 · 0 comments
Labels
actionable Items in the backlog waiting for an appropriate impl/fix good first issue Good for newcomers torchtune Issue/PR related to torchtune components triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@Jack-Khuu
Copy link
Contributor

🚀 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:

# Having the imports here allow running other evals without installing torchtune
from torchtune.utils import batch_to_device
from torchtune.data import (
format_content_with_images,
left_pad_sequence,
Message,
padded_collate_tiled_images_and_mask,
)
from torchtune.generation import generate, sample
from torchtune.modules.common_utils import local_kv_cache

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:

Alternatives

No response

Additional context

No response

RFC (Optional)

No response

@Jack-Khuu Jack-Khuu changed the title torchtune torchtune as an optional dependency: Lazy Import Mar 31, 2025
@Jack-Khuu Jack-Khuu added good first issue Good for newcomers actionable Items in the backlog waiting for an appropriate impl/fix triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module torchtune Issue/PR related to torchtune components labels Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable Items in the backlog waiting for an appropriate impl/fix good first issue Good for newcomers torchtune Issue/PR related to torchtune components triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
Development

No branches or pull requests

1 participant