-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Allow exposing more functions during initial template expansion #159554
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
base: main
Are you sure you want to change the base?
Allow exposing more functions during initial template expansion #159554
Conversation
Also adds a `_register_hook` utility, and documents & type annotates PartialRender.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/159554
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 4 New Failures, 2 Unrelated FailuresAs of commit 4c5f0c4 with merge base 2a286cb ( NEW FAILURES - The following jobs have failed:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
@pytorchbot label "topic: not user facing" |
@laithsakka want to take this ? |
these failures seem to be coming from the |
have added an |
don't think the 'new failures' relate to me: they're all
the single 'flaky' failure is for the same reason too. locally, two of the 'newly-failing' tests pass but i don't have enough memory for the other two. |
can you explain in the summary more what is the user case of this change, and some context. |
assert hook != "finalized", "hook_key can only be called once" | ||
self._code = self._code.replace(hook_key, hook()) | ||
|
||
self.replacement_hooks[hook_key] = "finalized" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you consider using None as proxy for finalized?
MaybeHookFn being Optional[HookFn]
you can use FINALIZED=None.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, to be honest i kept it as something other than None
because it actually used to be None
but got changed to something else; tbh i'm not totally sure the reason for the change (i can't find any references to FINALIZED_HOOK
outside of PartialRender
). i just made it a literal cause i couldn't see a way to type-annotate the raw object()
nicely.
|
||
def _register_extra_template_env_fns(self, *fns: Callable[..., Any]): | ||
""" | ||
Register some extra functions to expose when performing the initial |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain more what "to expose" means here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess you could say it means "to make available to be used by jinja expressions": jinja template strings can include expressions inside double curly brackets, and these expressions can include things like calls to python functions. the template_env
dictionary being passed to template.render
inside TritonTemplateKernel.render
is laying out what functions you want to be in scope for any expressions in the template being rendered.
shall i add more info to the comment along these lines?
the main use case i had for this was for people implementing their own triton inductor backends, who'd want to reuse most existing constructs but may want to use their own hooks when rendering template kernels; at the moment the list of hooks passed to |
Also adds a
_register_hook
utility, and documents & type annotatesPartialRender
.cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @chenyang78 @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben