Skip to content

fix: avoid shadowing Python stdlib profile module - #20

Open
renflowerz wants to merge 1 commit into
RightNow-AI:mainfrom
renflowerz:fix/profile-stdlib-shadowing
Open

fix: avoid shadowing Python stdlib profile module#20
renflowerz wants to merge 1 commit into
RightNow-AI:mainfrom
renflowerz:fix/profile-stdlib-shadowing

Conversation

@renflowerz

Copy link
Copy Markdown

Summary

  • prevent the repository's profile.py CLI from breaking Python's stdlib cProfile import
  • expose the stdlib profile API only when the file is imported as the module named profile
  • keep the existing AutoKernel CLI path unchanged when profile.py is executed
  • add regression tests for both the stdlib API and a real cProfile.run() call from the repository root

Problem

From the repository root, Python resolves import profile to AutoKernel's profile.py instead of the standard-library module. cProfile imports profile by name and expects _Utils, run, and runctx, so the shadowed import fails while Torch/Transformers imports are initializing.

Before:

profile resolves to: .../autokernel/profile.py
AttributeError: module 'profile' has no attribute 'run'

After:

import cProfile; cProfile.run('sum(range(10))')
# succeeds from the repository root

The normal CLI still imports Torch and executes the existing profiler implementation when __name__ == "__main__".

Tests

  • python3 -m unittest discover -s tests -v — Python 3.14, pass
  • .venv/bin/python -m unittest discover -s tests -v — Python 3.10, pass
  • 0652 B200 project venv:
    • compatibility tests pass
    • from transformers import AutoModelForCausalLM succeeds from repository root
    • uv run profile.py --help succeeds
    • real LLaMA profile smoke succeeds and writes a 20 KB JSON report
  • python3 -m py_compile profile.py tests/test_profile_module_compat.py
  • git diff --check

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.

1 participant