Skip to content

Fix for RuntimeError: Expected a single top-level function#112

Open
rossdonald wants to merge 1 commit intolshqqytiger:mainfrom
rossdonald:autocast_mode-fix
Open

Fix for RuntimeError: Expected a single top-level function#112
rossdonald wants to merge 1 commit intolshqqytiger:mainfrom
rossdonald:autocast_mode-fix

Conversation

@rossdonald
Copy link
Copy Markdown

Fixes a RuntimeError that occurs during startup #13 #33
Expected a single top-level function: modules\dml\amp\autocast_mode.py

The JIT compiler cannot resolve the source code of these dynamically-generated, anonymous lambda functions, which is a requirement for its scripting process. When kornia attempts to script a function or class that uses one of these patched operations, the JIT compilation fails.

An instance of _AutocastForwarder is now used to patch each operation. This provides a stable, inspectable object that the PyTorch JIT compiler can correctly handle. functools.update_wrapper is also used to ensure the wrapper is transparent to introspection tools.

…ode.py

Replace lambda function with a dedicated wrapper class that provides a stable, inspectable object that the PyTorch JIT compiler can correctly handle.
@TheFerumn
Copy link
Copy Markdown

TheFerumn commented Sep 8, 2025

Does it actually changes anything ? I had this error for a long time but i actually can use Stable Diffusion just fine with it. I had some issues earlier and i tought they are connected but everything got fixed. Maybe upscaling is still broken with it i haven't tested because i just Hires fix and it works.

Edit: Anyway i will just swap the file and use it just in case

@rossdonald
Copy link
Copy Markdown
Author

Does it actually changes anything ?

Well it fixes the error :)
The existing code works, the error comes from something that isn't used. I just found the error annoying.

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