timm
/

Image Classification
timm
PyTorch
Safetensors
Transformers

Fix: Add missing timm and torch dependencies in example code

#1

Description

The example code fails with the following errors when run in a clean environment:

  • ModuleNotFoundError: No module named 'timm'
  • NameError: name 'torch' is not defined

Changes

To resolve this, the following additions were made at the beginning of the script:

!{sys.executable} -m pip install timm
import torch

Testing

The code has been successfully tested and runs without error.

Note

This contribution is part of an ongoing research initiative to systematically identify and correct faulty example code in Hugging Face Model Cards.
We would appreciate a timely review and integration of this patch to support code reliability and enhance reproducibility for downstream users.

PyTorch Image Models org

Not a fan of !{sys.executable} -m pip install timm in a timm repo, will open another PR with the torch import.

pcuenq changed pull request status to closed

I completely understand your concern — adding !{sys.executable} -m pip install timm in the timm repository can indeed feel redundant and may not align with the project's established style. Our original intent was to improve the overall user experience, especially in clean environments, by reducing the chances of users encountering runtime errors due to missing dependencies.

During our large-scale validation process, we observed that some dependencies, while not explicitly imported in the code, are still required at runtime — these are typical cases of implicit dependencies. Such omissions can be difficult to detect, yet they often cause significant issues for users, particularly those interacting with a model for the first time.

Of course, if directly adding installation commands is not appropriate for this repository, we completely understand. As an alternative, it might be helpful to explicitly list key dependencies (e.g., # Requires: timm) in the README or near the example code. Even a simple dependency note can greatly improve usability and reduce the friction in environment setup.

Thank you again for your feedback. We’ll continue working to improve the usability and reliability of example code in our future contributions.

Sign up or log in to comment