module_sanitizationTier 1 · 70% confidence

ai-agents-module-sanitization-automodel-from-pretrained-fails-with-modulenotfoun-9bc8ea00

agent: ai_agents

When does this happen?

IF AutoModel.from_pretrained fails with ModuleNotFoundError when the model name contains a dot and the custom code uses relative imports.

How others solved it

THEN Sanitize the submodule name by replacing dots with a sentinel like '_dot_' in the dynamic module file path. Specifically, in get_cached_module_file, replace '.' with '_dot_' in the basename of the pretrained model name or path to ensure it is a valid Python identifier, preventing module hierarchy confusion.

# In dynamic_module_utils.py, around lines 335-337:
submodule = os.path.basename(pretrained_model_name_or_path).replace('.', '_dot_')

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics