AutoModel from_pretrained does not recursively download relative imports

Background

I have the following setup:

My directory looks like:

|--modeling.py
|--backbone.py
|--modules.py

In modeling.py I have an import statement to backbone:

from .backbone import ...

and likewise in backbone.py I have an import statement to modules:

from .modules import ...

My auto_map references modeling.py:

config.auto_map = {"AutoModel": "modeling.[some_class_in_this_file]"}

Now, I push a model to the hub and I also upload all 3 files to the repo.

Issue

However, when I try to use AutoModel.from_pretrained on my repo, I get a FileNotFoundError because for some reason modules.py was not cloned/pulled to the HF_HOME dir:

FileNotFoundError: [Errno 2] No such file or directory: '<HF_HOME>/transformers_modules/<repo>/modules.py'

I understand that the necessary relative imports are obtained recursively as here.

How come the relevant files aren’t also pulled/cloned recursively?

3 Likes