Relative imports are quirky and not well documented

When uploading a custom model that has multiple files to HuggingFace Hub, the documentation passingly mentions that “relative imports” are allowed if all files are in the same directory, but it turns out that only a specific format of relative import is supported.

Let’s say I have models and and the former wants to import the latter. The first two methods I used for relative importing didn’t work with weird errors and only the third one (that defies Google style guides is permitted):

  1. relative at module level:
from . import my_config

This leads to an error like the following:

ImportError: cannot import name 'my_config' from 'transformers_modules.<user>.<repo>.<branch>' (/Users/farzad/.cache/huggingface/modules/transformers_modules/farzadab/test-uv-pipeline/d66aec12954c4e0382d482f1efe0e5ef79c6e310/
  1. normal import as top-level:
import my_config

The leads to the error:

ImportError: This modeling file requires the following packages that were not found in your environment: my_config. Run `pip install my_config`
  1. the only one that works (which I’d rather not use since it violates Google style guides):
from .my_config import MyConfig

I believe this should be documented better or the error messages should be improved.
Also I’d appreciate it if option #1 was also allowed for consistency.