gaogaotiantian / viztracer

VizTracer is a low-overhead logging/debugging/profiling tool that can trace and visualize your python code execution.
https://viztracer.readthedocs.io/
Apache License 2.0
5.21k stars 385 forks source link

TypeError: CodeMonkey.compile() got an unexpected keyword argument '_feature_version' #456

Closed seniorsolt closed 3 months ago

seniorsolt commented 3 months ago

Error arised when trying to track --log_attr https://github.com/Nerogar/OneTrainer.

(venv) PS C:\Users\Max\Desktop\OneTrainer> viztracer --log_attr . --tracer_entries 10000000 --exclude_files C:\Users\Max\Desktop\OneTrainer\venv\Lib\site-packages\torch -- scripts\train_ui.py Total Entries: 59902
Use the following command to open the report: vizviewer C:\Users\Max\Desktop\OneTrainer\result.json Traceback (most recent call last): File "C:\Users\Max\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\Max\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\Max\Desktop\OneTrainer\venv\Scripts\viztracer.exe__main.py", line 7, in File "C:\Users\Max\Desktop\OneTrainer\venv\lib\site-packages\viztracer\main.py", line 671, in main success, err_msg = ui.run() File "C:\Users\Max\Desktop\OneTrainer\venv\lib\site-packages\viztracer\main.py", line 317, in run return self.run_command() File "C:\Users\Max\Desktop\OneTrainer\venv\lib\site-packages\viztracer\main.py", line 449, in run_command return self.run_code(code, main_mod.dict) File "C:\Users\Max\Desktop\OneTrainer\venv\lib\site-packages\viztracer\main.py", line 361, in run_code exec(code, global_dict) File "C:\Users\Max\Desktop\OneTrainer\scripts\train_ui.py", line 6, in from modules.ui.TrainUI import TrainUI File "C:\Users\Max\Desktop\OneTrainer\modules\ui\TrainUI.py", line 10, in import torch File "C:\Users\Max\Desktop\OneTrainer\venv\lib\site-packages\torch\init__.py", line 1539, in from .functional import
# noqa: F403 File "C:\Users\Max\Desktop\OneTrainer\venv\lib\site-packages\torch\functional.py", line 9, in import torch.nn.functional as F File "C:\Users\Max\Desktop\OneTrainer\venv\lib\site-packages\torch\nn__init.py", line 1, in from .modules import * # noqa: F403 File "C:\Users\Max\Desktop\OneTrainer\venv\lib\site-packages\torch\nn\modules\init__.py", line 2, in from .linear import Identity, Linear, Bilinear, LazyLinear File "C:\Users\Max\Desktop\OneTrainer\venv\lib\site-packages\torch\nn\modules\linear.py", line 7, in from .. import functional as F File "C:\Users\Max\Desktop\OneTrainer\venv\lib\site-packages\torch\nn\functional.py", line 3741, in def upsample(input: Tensor, size: Optional[int] = None, scale_factor: Optional[float] = None, mode: str = "nearest", align_corners: Optional[bool] = None) -> Tensor: # noqa: F 811,B950 File "C:\Users\Max\Desktop\OneTrainer\venv\lib\site-packages\torch_jit_internal.py", line 889, in _overload _check_overload_body(func) File "C:\Users\Max\Desktop\OneTrainer\venv\lib\site-packages\torch_jit_internal.py", line 862, in _check_overload_body parsed_def = parse_def(func) File "C:\Users\Max\Desktop\OneTrainer\venv\lib\site-packages\torch_sources.py", line 126, in parse_def py_ast = ast.parse(dedent_src) File "C:\Users\Max\AppData\Local\Programs\Python\Python310\lib\ast.py", line 50, in parse return compile(source, filename, mode, flags, TypeError: CodeMonkey.compile() got an unexpected keyword argument '_feature_version'

gaogaotiantian commented 3 months ago

Ah thanks. The argument _feature_version is internal and undocumented, but CPython itself uses it. I will fix it soon.

seniorsolt commented 3 months ago

Seems like just adding dummy arg _feature_version works def compile(self, source, filename, mode, flags=0, dont_inherit=False, optimize=-1, _feature_version=-1)

Taking this opportunity, I want to thank you for the tool. For a while, I was experimenting with other debuggers and even tried to write my own visualizer, but today I came across VizTracer and felt a bit sad. It already has everything implemented)

gaogaotiantian commented 3 months ago

I'm glad that it helped :) Yes I believe this is not hard to fix. In the meantime you can fix your local copy to make your stuff work. I will fix this in mainline soon but release takes a while too.