← Back to Pull requests

[perf, hardware] feat: platform hooks for the torch profiler's device activity and extra kwargs #8711

Closed
unknown closed this pull request without merging on Nov 18, 2026 02:28 UTC
View on GitHub
unknown unknown commented on Nov 17, 2026 00:08 UTC
Author

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 extra torch.profiler.profile arguments it needs, instead of each hardware plugin patching get_torch_profiler.

Today get_torch_profiler only knows the device activities torch ships (cuda, xpu, ...). Out-of-tree backends such as TPU (torch_tpu reports PrivateUse1 and needs its TpuProfilerConfig as experimental_config to write an XProf trace) or Cambricon MLU therefore patch verl from verl-hardware-plugin. The MLU plugin carries a near-copy of get_torch_profiler for this reason, which has to track every change here.

  • PlatformBase gets two optional hooks, with defaults that keep today's behavior:

  • - torch_profiler_activity(): default None, meaning torch's own activity for device_name.
    - torch_profiler_kwargs(save_path, rank): default {}.
  • get_torch_profiler asks the active platform for both. It uses the activity only if it is a torch.profiler.ProfilerActivity and the kwargs only if they are a mapping; otherwise it falls back to the existing DEVICE_ACTIVITIES lookup. 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 (PlatformTPU implements both hooks: +28 lines, no patch). It replaces the plugin's get_torch_profiler patch 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

  • Search for similar PRs. Paste at least one query link here: https://github.com/verl-project/verl/pulls?q=is%3Apr+is%3Aopen+torch+profiler+platform

  • Format the PR title as [{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 the PlatformBase defaults, a platform without hooks keeping the device lookup, an out-of-tree PrivateUse1 platform whose activity and experimental_config reach torch.profiler.profile, and kwargs being skipped when there is no device activity.

  • verl-hardware-plugin's profiler tests against this branch: 31 passed, including the MLU suite that checks verl's profiler behaves identically on xpu / cuda / npu / metax / tpu with the MLU patch installed.

  • No regressions on other devices. Same environment, main (909bb913) vs this branch; every failure below fails identically on both and comes from the environment (no nvtx / 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 run passes on the changed files.
  • API and Usage Example

    class PlatformMyAccel(PlatformBase):
        def torch_profiler_activity(self):
            return torch.profiler.ProfilerActivity.PrivateUse1
    
        def torch_profiler_kwargs(self, save_path, rank):
            return {"experimental_config": MyAccelProfilerConfig(run_dir=save_path, worker_rank=str(rank))}
    

    User config is unchanged (global_profiler.tool=torch, steps, ranks, ...).

    Design & Code Changes

  • verl/plugin/platform/platform_base.py: torch_profiler_activity() and torch_profiler_kwargs() with no-op defaults.

  • verl/utils/profiler/torch_profile.py: _call_platform_hook (an optional call); the activity falls back to DEVICE_ACTIVITIES; the platform's kwargs are merged into torch.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

  • Read the Contribute Guide.

  • Apply pre-commit checks (on the changed files).

  • Add / Update the documentation. (Docstrings on the new hooks.)

  • Add unit or end-to-end test(s) to the CI workflow to cover all the code.

  • Once your PR is ready for CI, send a message in the ci-request channel.

  • If your PR is related to the recipe submodule, please also update the reference to the submodule commit. (Not related.)
  • Diff: 648 lines (+486 / -162) across 8 files Reviewer: jialei777 Review duration: 1579m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52.0% (MEDIUM) · Higher = larger blast radius
    52.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%