Skip to content

[baseten] fix(model): tolerate missing remote-code siblings in check_imports hook - #21

Merged
ShreyaRavi merged 6 commits into
trainers-mainfrom
shreya/fix-recursive-check-imports-cold-cache
Jul 17, 2026
Merged

[baseten] fix(model): tolerate missing remote-code siblings in check_imports hook#21
ShreyaRavi merged 6 commits into
trainers-mainfrom
shreya/fix-recursive-check-imports-cold-cache

Conversation

@ShreyaRavi

Copy link
Copy Markdown

Problem

The check_imports hook from #? (b4072116, carried via f9c16ee2) walks transitive relative imports of remote-code modules by opening files on disk (get_relative_import_files). On the hub path, transformers calls check_imports before downloading the module's relative imports, so on a cold/partial HF cache the walk opens a file that isn't there yet:

FileNotFoundError: .../models--moonshotai--Kimi-K2.6/snapshots/7eb5002f.../modeling_deepseek.py

Every trainer rank dies at model build. Deterministic on cold caches for any trust_remote_code model with relative imports (Kimi K2.x, etc.); masked on warm caches and pre-staged local dirs, which is why it wasn't seen when the hook landed. Root-caused from baseten/trainers benchmarking runs of moonshotai/Kimi-K2.6 (jobs qex2o23 fail / 31yljg3 pass with files materialized).

Fix

Existence-guarded BFS instead of the blind walk. Missing siblings are returned by name: get_cached_module_file downloads each named module and re-enters this hook on it, so deeper imports are covered on that pass (verified against transformers 5.x dynamic_module_utils source).

  • Local dir (all files present — the case the hook was built for): unchanged result, full transitive closure.
  • Hub + cold cache: no crash; chain materializes hop-by-hop via caller re-entry.
  • Hub + stale module cache: closure through existing files still surfaces deps of already-copied members.

Testing

  • New unit test: 4 cases (full dir, cold cache, re-entry after download, circular imports).
  • Same 4 cases validated against the installed transformers 5.x helpers directly.
  • End-to-end: Kimi-K2.6 4x8xB200 trainer boot on a cold-cache workspace fails at modeling_deepseek.py without materialized siblings and passes model build with them (equivalent prefetch).

🤖 Generated with Claude Code

ShreyaRavi and others added 4 commits July 17, 2026 13:24
…imports hook

The recursive check_imports hook walks transitive relative imports by
opening files on disk, but on the hub path transformers calls
check_imports before downloading the module's relative imports — on a
cold HF cache the walk dies with FileNotFoundError (Kimi-K2.6:
modeling_deepseek.py). Guard the walk on file existence and return
missing siblings by name: get_cached_module_file downloads each named
module and re-enters the hook on it, so deeper imports are covered on
that pass. Local-dir loads (all files present) still return the full
transitive closure.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…hed_module_file

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@@ -0,0 +1,13 @@
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this file?

@ShreyaRavi ShreyaRavi Jul 17, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's standard for everything in models/, keeping it to match convention.

generally __init__.py is what you use to tell Python this is a package (so its contents can be imported)

@iankorovinsky iankorovinsky left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left one comment (non-blocking)

@ShreyaRavi
ShreyaRavi merged commit 0336cb5 into trainers-main Jul 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants