8000 [internal] Expose additional metadata to compilation callbacks by xmfan · Pull Request #153596 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

[internal] Expose additional metadata to compilation callbacks #153596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: gh/xmfan/238/base
Choose a base branch
from

Conversation

xmfan
Copy link
Member
@xmfan xmfan commented May 15, 2025

Stack from ghstack (oldest at bottom):

These hooks are used by internal stuck job detection to associate compilation events with the compile lease. Previously, we only had events for Dynamo and Inductor compilation. And recently, the callback handler was updated to ignore nested events. So the Inductor event was only really used by lazy backward.

Here, I remove the inductor event, and add an explicit lazy backward one. Additionally, 10000 I add other runtime compilation events: autotuning and cudagraphs. I also expose the CompileId as a string to avoid imports, this will let internal UIs track each graph's contribution to the timeout.

class CallbackTrigger(enum.Enum):
    # most common case, dynamo attempts to trace a new frame
    DYNAMO = 1
    # backward compilation can be deferred to runtime
    LAZY_BACKWARD = 2
    # some backends autotune at runtime
    TRITON_AUTOTUNING = 3
    # cudagraphs record at runtime
    CUDAGRAPH_RECORDING = 4

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @chenyang78 @kadeng @muchulee8 @amjames @chauhang @aakhundov

[ghstack-poisoned]
Copy link
pytorch-bot bot commented May 15, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/153596

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 5d56d1e with merge base 82dc345 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

[ghstack-poisoned]
xmfan added a commit that referenced this pull request May 15, 2025
@xmfan xmfan changed the title [internal] Extend compilation callback with CallbackTrigger metadata [internal] Expose additional metadata to compilation callbacks May 15, 2025
@xmfan xmfan added the topic: not user facing topic category label May 15, 2025
[ghstack-poisoned]
xmfan added a commit that referenced this pull request May 15, 2025
Comment on lines +154 to +166
def on_compile_start(
callback: Callable[[CallbackArgs], None],
) -> Callable[[CallbackArgs], None]:
"""
Decorator to register a callback function for the start of the compilation.
"""
callback_handler.register_start_callback(callback)
return callback


def on_compile_end(callback: Callable[[], None]) -> Callable[[], None]:
def on_compile_end(
callback: Callable[[CallbackArgs], None],
) -> Callable[[CallbackArgs], None]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to introduce new APIs? I am guessing this change will cause type errors as the callback function being passed needs to have CallbackArgs argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is the concern about backward compatibility? This is a private API and I didn't find any usage on github, we can address the internal type changes on the import diff. The "new API" offers a superset of the old, so I didn't see much value keeping it around.

[ghstack-poisoned]
xmfan added a commit that referenced this pull request May 16, 2025
@xmfan xmfan marked this pull request as ready for review May 16, 2025 14:12
@xmfan xmfan requested a review from bdhirsh as a code owner May 16, 2025 14:12
@xmfan xmfan requested review from masnesral and removed request for bdhirsh May 16, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0