Replies: 11 comments 19 replies
-
The current plan for TorchDynamo would involve dynamically enabling/disabling eval frame hooks. We would install the eval_frame hook on entry to a It might be possible to emulate this behavior by installing a persistent hook that checks the count of |
Beta Was this translation helpful? Give feedback.
-
I realized after our discussion that in the current "Pyston's JIT as an extension module" that we're working on, it's not quite safe to use A similar-but-different problematic case is a generator that is created before changing I think one approach to these issues would be to have some sort of hook that gets run before any Python code is executed, but I'm not aware of an existing one like this. |
Beta Was this translation helpful? Give feedback.
-
We need to:
Both Cinder and Pyston want to attach early in the process, and take over control of the interpreter. I think the best approach is to piggy back on the instrumentation mechanism of PEP 669, treating custom eval functions like profiling. Each call would be instrumented, so that it would call the custom eval function without additional checks. |
Beta Was this translation helpful? Give feedback.
-
Would the |
Beta Was this translation helpful? Give feedback.
-
FWIW, there has been some discussion about generating the eval loop at build time. If we do that right, the same tooling could be used to generate custom eval loops outside CPython. |
Beta Was this translation helpful? Give feedback.
-
I'd like to make a few concrete proposals, to see whether they suit Pyston and/or Cinder.
I think that covers it. Basically, implement your preload module in C and call |
Beta Was this translation helpful? Give feedback.
-
I think using an environment variable makes sense, given the issue with sub-processes. |
Beta Was this translation helpful? Give feedback.
-
We have some use for exposing object offsets to JITed code. For example, sometimes the JITed code would like to reach into a Python object like a |
Beta Was this translation helpful? Give feedback.
-
I was unaware of this discussion here earlier and I'm not sure if it's still relevant, but now that I'm looking at it, I'd like to point out that -Xpresite= is now a thing. Currently it's used for reliable gathering of stdlib test coverage, and it requires a Py_DEBUG build. To me it looks like what |
Beta Was this translation helpful? Give feedback.
-
yeah, I think |
Beta Was this translation helpful? Give feedback.
-
I think this would be useful for the Cinder JIT. @ambv do you see any downsides to enabling |
Beta Was this translation helpful? Give feedback.
-
This was discussed in the PyCon US 2022 open space, the purpose of this thread is to capture what was discussed (disclaimer: just the PEP-523 aspects, not the entire discussion).
@markshannon had concerns with the current state of PEP-523, which requires checking for
eval_frame
inefficiently in the interpreter and in specialized code.there was general agreement that for JIT use-cases, changing PEP-523 to allow hooking in initially (and taking total control over the interpreter) and not per-function would be sufficient, and will not interfere with further optimizations in the default frame evaluator and specializations. it was pointed out that this might not be the case for debuggers. if my understanding is correct, it should be sufficient also for TorchDynamo's use-case (confirmation from @jansel needed).
looking at the 3.11 code now, it appears that some (most?) of the problematic checks are actually missing, making the current situation pretty close to what's described above. so perhaps all that's needed is to update PEP-523 to make the assumptions about at what point it can be invoked explicit?
PEP-523 users that are interested in taking over full control over the interpreter will need to plug in "early enough" (to be defined). if such users delegate back to
_PyEval_EvalFrameDefault
, they might lose some or all control (or fight against the default frame eval) becauseeval_frame
is not checked inside the default eval loop and in the specializer. to guarantee control, users will need to reimplement the eval loop (likely by duplicating it in their extension and modifying it accordingly).Beta Was this translation helpful? Give feedback.
All reactions