[perf, hardware] feat: platform hooks for the torch profiler's device activity and extra kwargs #8711
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 648 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.387
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8711"
general
weight: 0.35
jialei777
What does this PR do?
Lets an accelerator platform tell verl's torch profiler (
global_profiler.tool=torch) which device activity to record and which extratorch.profiler.profilearguments it needs, instead of each hardware plugin patchingget_torch_profiler.Today
get_torch_profileronly knows the device activities torch ships (cuda,xpu, ...). Out-of-tree backends such as TPU (torch_tpu reportsPrivateUse1and needs itsTpuProfilerConfigasexperimental_configto write an XProf trace) or Cambricon MLU therefore patch verl from verl-hardware-plugin. The MLU plugin carries a near-copy ofget_torch_profilerfor this reason, which has to track every change here.PlatformBasegets two optional hooks, with defaults that keep today's behavior:-
torch_profiler_activity(): defaultNone, meaning torch's own activity fordevice_name.-
torch_profiler_kwargs(save_path, rank): default{}.get_torch_profilerasks the active platform for both. It uses the activity only if it is atorch.profiler.ProfilerActivityand the kwargs only if they are a mapping; otherwise it falls back to the existingDEVICE_ACTIVITIESlookup. So platforms without the hooks, and duck-typed platforms such as test mocks, behave exactly as before.Plugin side, as the first user: verl-project/verl-hardware-plugin#160 (
PlatformTPUimplements both hooks: +28 lines, no patch). It replaces the plugin'sget_torch_profilerpatch proposed in verl-project/verl-hardware-plugin#159.Not a duplicate: no open PR touches the torch profiler's device resolution (search below). #8289 adds profiling for independent Ray actors, a different part of the profiler.
Checklist Before Starting
[{modules}] {type}: {description}(This will be checked by the CI)Test
pytest tests/utils/test_torch_profile.py: 54 passed (CPU-only torch). The existing tests are unchanged. New tests cover thePlatformBasedefaults, a platform without hooks keeping the device lookup, an out-of-treePrivateUse1platform whose activity andexperimental_configreachtorch.profiler.profile, and kwargs being skipped when there is no device activity.main(909bb913) vs this branch; every failure below fails identically on both and comes from the environment (nonvtx/ CUDA, optional packages):| Suite |
main| this PR | Failing only with this PR ||---|---|---|---|
| verl profiler + platform tests (
tests/utils/test_profile.py,test_profiler_markers.py,test_check_profiler_output.py,tests/plugin/test_platform_abstraction.py) | 17 failed (all NVTX / server-profiler), 136 passed | 17 failed, 140 passed | none ||
tests/trainer/ppo/v1/test_rollout_profiling_on_cpu.py| 10 passed | 10 passed | none || verl-hardware-plugin CPU suite (MLU, XPU, MetaX, MUSA, Neuron, ROCm, Enflame, Supa, Iluvatar, TPU) | 18 failed, 567 passed | 18 failed, 568 passed | none |
pre-commit runpasses on the changed files.API and Usage Example
User config is unchanged (
global_profiler.tool=torch,steps,ranks, ...).Design & Code Changes
verl/plugin/platform/platform_base.py:torch_profiler_activity()andtorch_profiler_kwargs()with no-op defaults.verl/utils/profiler/torch_profile.py:_call_platform_hook(an optional call); the activity falls back toDEVICE_ACTIVITIES; the platform's kwargs are merged intotorch.profiler.profile(...)only when device activity is recorded.tests/utils/test_torch_profile.py: 4 new tests.AI assistance was used for this change; I reviewed every changed line and the test results.
Checklist Before Submitting
ci-requestchannel.recipesubmodule, please also update the reference to the submodule commit. (Not related.)