Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N
There was a problem hiding this comment.
Code Review
This pull request introduces atomic merging of model shards in evo2/models.py by writing to a temporary directory before replacing the final weights file, and adds CPU-only unit tests in tests/test_cpu.py to verify this behavior. The feedback suggests ensuring final_weights_path is converted to an absolute path to guarantee the temporary directory is created on the same filesystem for an atomic os.replace. Additionally, it is recommended to clear cached evo2 modules from sys.modules in the test setup to prevent cached imports from bypassing the mocked dependencies.
| with tempfile.TemporaryDirectory(dir=os.path.dirname(final_weights_path)) as temp_dir: | ||
| temp_weights_path = os.path.join(temp_dir, filename) |
There was a problem hiding this comment.
If final_weights_path is a relative path (or if os.path.dirname(final_weights_path) resolves to an empty string), tempfile.TemporaryDirectory(dir="") will fallback to the system's default temporary directory (e.g., /tmp). This can place the temporary file on a different filesystem/mount point than the final destination, which prevents os.replace from being an atomic operation and can cause performance issues or failures.
Using os.path.abspath ensures we always get a valid absolute directory path on the same filesystem.
final_weights_dir = os.path.dirname(os.path.abspath(final_weights_path))
with tempfile.TemporaryDirectory(dir=final_weights_dir) as temp_dir:
temp_weights_path = os.path.join(temp_dir, filename)| with mock.patch.dict(sys.modules, {**modules, 'transformer_engine': None}): | ||
| loaded = importlib.import_module('evo2.models') |
There was a problem hiding this comment.
If evo2 or evo2.models was already imported by another test in the suite, importlib.import_module will return the cached module from sys.modules instead of performing a fresh import under the mock.patch.dict context. This would bypass the mocked vortex modules and potentially fail or use the real vortex library.
To ensure the test is robust and independent of other tests, we should remove any existing evo2 modules from sys.modules before importing.
| with mock.patch.dict(sys.modules, {**modules, 'transformer_engine': None}): | |
| loaded = importlib.import_module('evo2.models') | |
| for k in list(sys.modules.keys()): | |
| if k == 'evo2' or k.startswith('evo2.'): | |
| sys.modules.pop(k, None) | |
| with mock.patch.dict(sys.modules, {**modules, 'transformer_engine': None}): | |
| loaded = importlib.import_module('evo2.models') |
|
Let me know if you have any thoughts on this one. |
There's a bug in
Evo2.load_evo2_model: it merges shards into the cache file that the next load accepts based on its existence.If opening the second shard fails after writing the first shard's 12 bytes, retrying accepts those 12 bytes as the checkpoint instead of merging both shards into 25 bytes.
This merges into a temporary directory on the destination filesystem, closes the file, then publishes it with
os.replace.Test:
test_failed_merge_is_not_reused_on_retryintests/test_cpu.pyfails on main and passes here. Both CPU checkpoint tests pass on Python 3.11 and 3.12; syntax checks andgit diff --checkpass. Model loading and downloads are mocked.🤖 Generated with Claude Code
https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N