Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 10, 2025. It is now read-only.
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

torchtune as an optional dependency: Lazy Import #1519

Open
Assignees
Labels
actionableItems in the backlog waiting for an appropriate impl/fix good first issueGood for newcomers torchtuneIssue/PR related to torchtune components triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
@Jack-Khuu

Description

🚀 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

Metadata

Metadata

Labels

actionableItems in the backlog waiting for an appropriate impl/fix good first issueGood for newcomers torchtuneIssue/PR related to torchtune components triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

Status

Ready

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /