Skip to content

Add sys.modules registration - #105

Merged
NinaCai merged 4 commits into
mainfrom
nina-evaluation-harness
Sep 17, 2026
Merged

NinaCai merged 4 commits into
mainfrom
nina-evaluation-harness

Conversation

@NinaCai

@NinaCai NinaCai commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator
  • without the sys.modules registration it raises the identical AttributeError; with it, the import succeeds.

from future import annotations + a dataclass would fail without this change.

  • when comparing diff, use the specific datatype to avoid OOM.
  • change code_adapt.py so that when it fails adaption due to large context, it will explicitly show an error.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates MaxKernel/evaluation/harness_code.py to register a module in sys.modules before executing it, preventing failures during string annotation resolution. Feedback highlights a potential issue where unconditionally popping the module on failure could delete a pre-existing module, and suggests capturing and restoring the previous module state instead.

Comment on lines +23 to +28
sys.modules[module_name] = module
try:
spec.loader.exec_module(module)
except Exception:
sys.modules.pop(module_name, None)
raise

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If module_name was already present in sys.modules before calling load_module_from_path, unconditionally popping it on failure will delete the pre-existing module instead of restoring it. It is safer to capture the previous value of sys.modules[module_name] and restore it if execution fails.

Suggested change
sys.modules[module_name] = module
try:
spec.loader.exec_module(module)
except Exception:
sys.modules.pop(module_name, None)
raise
old_module = sys.modules.get(module_name)\n sys.modules[module_name] = module\n try:\n spec.loader.exec_module(module)\n except Exception:\n if old_module is None:\n sys.modules.pop(module_name, None)\n else:\n sys.modules[module_name] = old_module\n raise

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

If it gets to Exception, it will fail anyway.

return avg_wall_time, xprof_time


def diff_metrics(b, o, chunk_elems=1 << 24):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this function added because the code can run into OOM during the diff calculation? It might be beneficial if we can make this comment easier to understand.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Config 3 (csa_decode_bs512) has a uint8 cache of (32769, 256, 4, 128) = 4 GiB. b and o are host numpy arrays by this point, so (b - o) / b is a numpy true division → promotes to float64 on the host. Then jnp.abs(...) ships it to the TPU as f32: a 16 GiB argument plus a 16 GiB result = 32.00 GiB against a 31.25 GiB chip, overflowing by 773 M.

@@ -266,8 +315,9 @@ def main():
if b.shape != o.shape:
raise ValueError(f"Shape mismatch: {b.shape} vs {o.shape}")
is_correct = is_correct and bool(jnp.allclose(b, o, atol=curr_atol, rtol=curr_rtol))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If the diff can make OOM, why this line will not make OOM?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

OOM happens in abs calculation. allclose survives because it's jitted and XLA fuses the promotion

@NinaCai
NinaCai merged commit f5fa5ed into main Sep 17, 2026
8 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