core.tuning.interception#
Carrying out an :class:AutotunePolicy against Triton’s autotuner.
This is the only module that touches Triton internals. Everything else works against the policy and the table, so replacing this file is all that is needed when Triton grows a supported hook, or when the upstream packages stop needing the intervention at all.
Module Contents#
Functions#
The policy currently installed, if any. |
|
Hash of every autotune choice this rank has made so far. |
|
The per-(kernel, shape) choices this rank has made. |
|
Compare configs for kernel/shape keys observed on multiple ranks. |
|
Run :func: |
|
Apply |
|
Triton’s |
|
Data#
API#
- core.tuning.interception.logger#
‘getLogger(…)’
- core.tuning.interception._installed#
False
- core.tuning.interception._policy: megatron.core.tuning.policy.AutotunePolicy | None#
None
- core.tuning.interception._tables: dict#
None
- core.tuning.interception._selected_configs: weakref.WeakKeyDictionary#
‘WeakKeyDictionary(…)’
- core.tuning.interception._scopes: weakref.WeakKeyDictionary#
‘WeakKeyDictionary(…)’
- core.tuning.interception._logged_singletons: weakref.WeakSet#
‘WeakSet(…)’
- core.tuning.interception._choice_log: dict#
None
- core.tuning.interception._unverified: dict#
None
- core.tuning.interception._verified: dict#
None
- core.tuning.interception._tune_records: dict#
None
- core.tuning.interception._record_rank: int | None#
None
- core.tuning.interception._enumerated: set#
‘set(…)’
- core.tuning.interception.active_policy() megatron.core.tuning.policy.AutotunePolicy | None#
The policy currently installed, if any.
- core.tuning.interception._scope(autotuner, policy: megatron.core.tuning.policy.AutotunePolicy)#
- core.tuning.interception._enumerate(qualified: str, count: int, state: str) None#
- core.tuning.interception._record_choice(
- arch: str,
- qualified: str,
- key: str,
- config,
- pinned: bool,
- core.tuning.interception._record_winner(arch: str, qualified: str, key: str, config) None#
- core.tuning.interception._record_file(record_path: str, rank: int) str#
- core.tuning.interception._check_record_path(record_path: str) None#
- core.tuning.interception._dump_records() None#
- core.tuning.interception.choice_digest() str#
Hash of every autotune choice this rank has made so far.
- core.tuning.interception.choice_log() dict#
The per-(kernel, shape) choices this rank has made.
- core.tuning.interception.verify_choices(group=None) bool#
Compare configs for kernel/shape keys observed on multiple ranks.
Call where all ranks arrive, such as a step boundary. Calling it at the moment of choice would deadlock: ranks reach a given kernel at different times, so they would not agree on whether to take part in the collective.
Each check exchanges only the choices made since the previous check and compares them with those already agreed on, so once every kernel and shape has been seen a check moves an empty payload. Pipeline stages and expert ranks can execute different kernels or shapes; an absent key is not a conflicting choice. Agreement only covers observed choices; it does not establish numerical determinism or equal coverage.
- core.tuning.interception.maybe_verify_choices(iteration: int, group=None) bool | None#
Run :func:
verify_choicesif the policy asks for a check atiteration.This is the cadence behind
AutotunePolicy.verify_every; the training loop calls it once per step and the policy decides whether anything happens. ReturnsNonewhen no check ran, so a caller can tell “agreed” from “not asked”.
- core.tuning.interception.install(
- policy: megatron.core.tuning.policy.AutotunePolicy | collections.abc.Mapping | None = None,
- *,
- deterministic: bool = False,
Apply
policyto the whole process, replacing the previous one.Call during initialization, before kernels run. Megatron’s training initializer does this from the
--triton-autotune-*arguments; library callers that build models directly call it themselves.Noneapplies the default policy, and a mapping is converted. An omittedmodeis derived: a recording path selectsrecord,deterministicor PyTorch’s deterministic flag selectspinned, and anything elseauto. Repeated calls reuse the same adapter rather than nesting patches.Raises if the policy cannot be carried out, such as when its recording path is not writable or when Triton is installed without the autotuner this adapter patches; the previous policy then stays in place. Without Triton no kernel is autotuned, so there is nothing to patch.
- core.tuning.interception._reset_runtime_state() None#
- core.tuning.interception._autotuner_class()#
Triton’s
Autotuner, orNonewhen Triton is not installed.
- core.tuning.interception._install(policy: megatron.core.tuning.policy.AutotunePolicy) None#
- core.tuning.interception.__all__#
[‘active_policy’, ‘choice_digest’, ‘choice_log’, ‘install’, ‘maybe_verify_choices’, ‘verify_choices’…