-
Notifications
You must be signed in to change notification settings - Fork 16
[DEV] Support nested wrapper #70
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
Conversation
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.
Pull Request Overview
This PR enables support for nested trace wrappers while improving dynamic client addition and deduplication for instrumentation. Key changes include refactoring the Trace class to use an internal add_clients method, updating client instantiation to use a factory pattern via the Sanitizer abstract class, and cleaning up configuration and patching code.
- Updated Trace class to support stacking and client deduplication
- Refactored sanitizer instantiation to use a class-based factory with NullSanitizer
- Header and import cleanup to consistently reference configuration via cfg
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
triton_viz/core/trace.py | Refactored Trace: added _normalize_client and add_clients methods |
triton_viz/core/patch.py | Updated progress reporting and sanitizer backend lookups |
triton_viz/core/config.py | Made sanitizer_backend lazy, deferring its check until first access |
triton_viz/core/client.py | Modified ClientManager: added add_clients; mutable default parameter |
triton_viz/clients/sanitizer/sanitizer.py | Switched to class-based sanitizer factory and added NullSanitizer |
tests/test_trace_add_clients.py | Added tests for client deduplication across stacked trace decorators |
tests/test_trace_add_clients.py
Outdated
""" | ||
@triton_viz.trace(("sanitizer", "profiler")) | ||
@triton_viz.trace("tracer") | ||
@triton_viz.trace(("sanitizer",)) # Duplicate Sanitizer (should be ignored) |
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.
It seems too complicated isn't it...Why not we just standardize the api to support only one of the possible use cases? It can be either an array of modes or nested annotations, but not both
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.
It's not hard for me to support both...
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 want to support nested wrapper because I want to deal with the legacy code that use @triton_viz.sanitizer
wrapper. With the new command-line tool triton-sanitizer
, there may be nested wrappers.
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.
It's not hard for me to support both...
It will be error-prone and complicate users. Let's just modify it to be either the first or the second convention.
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 prefer the second convention because
I want to deal with the legacy code that use @triton_viz.sanitizer wrapper.
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.
It's OK. Please update your code accordingly
raise ValueError("At least one client must be specified!") | ||
|
||
if not isinstance(client, (str, Client)): | ||
raise TypeError(f"Expected str or Client, got {type(client)}") | ||
|
||
def decorator(kernel) -> Trace: | ||
# When sanitizer is off, skip tracing and return the original kernel unchanged | ||
if cfg.sanitizer_backend == "off": | ||
return kernel | ||
|
||
# First-time wrapping | ||
if isinstance(kernel, JITFunction): |
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.
Have you tested this with @triton.autotune?
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.
No. Let me write a unittest with autotune.
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.
Maybe we can consider running all tests using CI.
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 just ran test/test_autotune_add.py
and it worked well.
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.
Let's fix the bugs before merging
…; add unittest for adding clients
Co-authored-by: Copilot <[email protected]>
91e1409
to
06741bf
Compare
@@ -5,9 +5,9 @@ name: Python application | |||
|
|||
on: | |||
push: | |||
branches: [ "main" ] | |||
branches: [] |
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.
Those changes are suspicious
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.
This change has been fixed in #71.
We use
branches-ignore:
- '**'
instead of
branches: []
to ignore all ci tests for now.
cd triton_viz | ||
pip install pre-commit | ||
pre-commit run --all-files | ||
# - name: Lint with pre-commit |
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.
ditto
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.
And why merge without making all tests passed?
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 want to focus on indirect load first and fix CI later.
As for CI problem, I figured out that once you set TRITON_INTERPRET=1
, triton will skip driver checking.
See https://github.com/triton-lang/triton/blob/d141ab8b1bfa8e8dc703459412cd827b09f80b21/python/triton/_internal_testing.py#L30
However, triton-viz cannot work with TRITON_INTERPRET=1
and needs to be fixed.
I will do this after I finish indirect load.
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.
Sure, it has to be compatible with TRITON_INTERPRET=1
tests/test_trace_add_clients.py
@trace
decorators.triton_viz/clients/sanitizer/sanitizer.py
NullSanitizer
forbackend == "off"
.SanitizerBruteForce
,SanitizerSymbolicExecution
, andNullSanitizer
withSanitizer.register(...)
.cfg
for backend lookup.triton_viz/core/client.py
ClientManager.__init__
defaults clients to an empty list.add_clients()
to append new clients with type-based deduplication.triton_viz/core/config.py
_sanitizer_backend
lazily; raises at first access if unset instead of on module import.triton_viz/core/patch.py
report_grid_execution_progress
andsanitizer_backend
with cfg.*.triton_viz/core/trace.py
_normalize_client()
andadd_clients()
for runtime client management and deduplication.trace()
decorator:Trace
, it appends clientsJITFunction
, it wraps once.Trace.__init__
now initializes an emptyClientManager
then adds clients viaadd_clients()
.