Repository navigation
[plugin] oot torch profiler activity support #31580
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -251,6 +251,14 @@ def get_cpu_architecture(cls) -> "CpuArchEnum": | |||||||||||||||||||||||||||||
| return CpuArchEnum.ARM | ||||||||||||||||||||||||||||||
| return CpuArchEnum.UNSPECIFIED | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def get_torch_profiler_activity_str(self) -> str: | ||||||||||||||||||||||||||||||
| """[Planned] Return the torch profiler activity string.""" | ||||||||||||||||||||||||||||||
| raise NotImplementedError | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def get_torch_profiler_activity(self) -> torch.profiler.ProfilerActivity: | ||||||||||||||||||||||||||||||
| """[Planned] Return the torch profiler activity.""" | ||||||||||||||||||||||||||||||
| raise NotImplementedError | ||||||||||||||||||||||||||||||
|
Comment on lines
+254
to
+260
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of raising
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||
| # Dunder helpers | ||||||||||||||||||||||||||||||
| # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |||||||||||||||||||||||||||||||||||||||||||
| from sglang.srt.environ import envs | ||||||||||||||||||||||||||||||||||||||||||||
| from sglang.srt.managers.io_struct import ProfileReqOutput | ||||||||||||||||||||||||||||||||||||||||||||
| from sglang.srt.model_executor.forward_batch_info import ForwardBatch, ForwardMode | ||||||||||||||||||||||||||||||||||||||||||||
| from sglang.srt.platforms import current_platform | ||||||||||||||||||||||||||||||||||||||||||||
| from sglang.srt.runtime_context import get_server_args | ||||||||||||||||||||||||||||||||||||||||||||
| from sglang.srt.utils import is_npu | ||||||||||||||||||||||||||||||||||||||||||||
| from sglang.srt.utils.torch_npu_patch_utils import apply_torch_npu_patches | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -221,6 +222,16 @@ class _ProfilerBase(ABC): | |||||||||||||||||||||||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||||||||||||||||||||||||
| def create(activities, with_stack, record_shapes, **kwargs): | ||||||||||||||||||||||||||||||||||||||||||||
| inners = [] | ||||||||||||||||||||||||||||||||||||||||||||
| if current_platform.is_out_of_tree(): | ||||||||||||||||||||||||||||||||||||||||||||
| if current_platform.get_torch_profiler_activity_str() in activities: | ||||||||||||||||||||||||||||||||||||||||||||
| inners.append( | ||||||||||||||||||||||||||||||||||||||||||||
| _ProfilerTorch( | ||||||||||||||||||||||||||||||||||||||||||||
| **kwargs, | ||||||||||||||||||||||||||||||||||||||||||||
| activities=activities, | ||||||||||||||||||||||||||||||||||||||||||||
| with_stack=with_stack, | ||||||||||||||||||||||||||||||||||||||||||||
| record_shapes=record_shapes, | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+225
to
+234
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To prevent potential
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| if ("CPU" in activities) or ("GPU" in activities): | ||||||||||||||||||||||||||||||||||||||||||||
| inners.append( | ||||||||||||||||||||||||||||||||||||||||||||
| _ProfilerTorch( | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -291,6 +302,12 @@ def start(self): | |||||||||||||||||||||||||||||||||||||||||||
| "CPU": torch.profiler.ProfilerActivity.CPU, | ||||||||||||||||||||||||||||||||||||||||||||
| "GPU": torch.profiler.ProfilerActivity.CUDA, | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if current_platform.is_out_of_tree(): | ||||||||||||||||||||||||||||||||||||||||||||
| activity_map[current_platform.get_torch_profiler_activity_str()] = ( | ||||||||||||||||||||||||||||||||||||||||||||
| current_platform.get_torch_profiler_activity() | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+306
to
+309
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| torchprof_activities = [ | ||||||||||||||||||||||||||||||||||||||||||||
| activity_map[a] for a in self.activities if a in activity_map | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
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.
If
get_torch_profiler_activity_str()returnsNone(or if it is not implemented), callinghasattr(torch.profiler.ProfilerActivity, None)will raise aTypeError. We should retrieve the values first and check if they are notNonebefore checking attributes and updating the map.