Skip to content

Add profilingSampleCount to decouple profiler sampling source from opCount (#2067)#2067

Open
mlunar-meta wants to merge 2 commits intometa-pytorch:mainfrom
mlunar-meta:export-D100730174
Open

Add profilingSampleCount to decouple profiler sampling source from opCount (#2067)#2067
mlunar-meta wants to merge 2 commits intometa-pytorch:mainfrom
mlunar-meta:export-D100730174

Conversation

@mlunar-meta
Copy link
Copy Markdown
Contributor

@mlunar-meta mlunar-meta commented Apr 14, 2026

Summary:

Add a profilingSampleCount_ pointer on CtranComm that allows callers to control which counter the profiler uses for sampling decisions. When set, the profiler samples based on the pointed-to counter instead of opCount. When null (default), existing behavior is preserved — opCount is used.

MCCL uses this to sample based on a new collectiveCount_ counter (incremented per allReduce call) rather than opCount, enabling independent sampling control.

Changes:

  • Add uint64_t* profilingSampleCount_ to CtranComm (nullptr = use opCount)
  • Add uint64_t collectiveCount_ to McclComm, incremented in allReduce
  • Wire profilingSampleCount_ to collectiveCount_ in McclComm::finishInit
  • Profiler::initForEachColl uses profilingSampleCount when set, else opCount
  • Add AUTODEPS fix for profiler_test BUCK (ncclx-cvars dep)
  • Add 2 test cases: override via profilingSampleCount, nullptr fallback to opCount

Differential Revision: D100730174

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 14, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync bot commented Apr 14, 2026

@mlunar-meta has exported this pull request. If you are a Meta employee, you can view the originating Diff in D100730174.

@meta-codesync meta-codesync bot changed the title Add profilingSampleCount to decouple profiler sampling source from opCount Add profilingSampleCount to decouple profiler sampling source from opCount (#2067) Apr 14, 2026
mlunar-meta added a commit to mlunar-meta/torchcomms that referenced this pull request Apr 14, 2026
…Count (meta-pytorch#2067)

Summary:

Add a `profilingSampleCount_` pointer on `CtranComm` that allows callers to control which counter the profiler uses for sampling decisions. When set, the profiler samples based on the pointed-to counter instead of opCount. When null (default), existing behavior is preserved — opCount is used.

MCCL uses this to sample based on a new `collectiveCount_` counter (incremented per allReduce call) rather than opCount, enabling independent sampling control.

Changes:
- Add `uint64_t* profilingSampleCount_` to CtranComm (nullptr = use opCount)
- Add `uint64_t collectiveCount_` to McclComm, incremented in allReduce
- Wire `profilingSampleCount_` to `collectiveCount_` in McclComm::finishInit
- Profiler::initForEachColl uses profilingSampleCount when set, else opCount
- Add AUTODEPS fix for profiler_test BUCK (ncclx-cvars dep)
- Add 2 test cases: override via profilingSampleCount, nullptr fallback to opCount

Differential Revision: D100730174
mlunar-meta added a commit to mlunar-meta/torchcomms that referenced this pull request Apr 14, 2026
…Count (meta-pytorch#2067)

Summary:
Pull Request resolved: meta-pytorch#2067

Add a `profilingSampleCount_` pointer on `CtranComm` that allows callers to control which counter the profiler uses for sampling decisions. When set, the profiler samples based on the pointed-to counter instead of opCount. When null (default), existing behavior is preserved — opCount is used.

MCCL uses this to sample based on a new `collectiveCount_` counter (incremented per allReduce call) rather than opCount, enabling independent sampling control.

Changes:
- Add `uint64_t* profilingSampleCount_` to CtranComm (nullptr = use opCount)
- Add `uint64_t collectiveCount_` to McclComm, incremented in allReduce
- Wire `profilingSampleCount_` to `collectiveCount_` in McclComm::finishInit
- Profiler::initForEachColl uses profilingSampleCount when set, else opCount
- Add AUTODEPS fix for profiler_test BUCK (ncclx-cvars dep)
- Add 2 test cases: override via profilingSampleCount, nullptr fallback to opCount

Differential Revision: D100730174
Summary:
Introduce a SamplingRegistry class in ctran/profiler/ that encapsulates the sampling decision (shouldTrace based on opCount % samplingWeight). The Profiler now reads the sampling weight from ctranConfig at construction instead of receiving it as a parameter at every initForEachColl() call.

This decouples the profiler sampling from the hardcoded NCCL_CTRAN_ALGO_PROFILING_SAMPLING_WEIGHT CVAR, allowing MCCL to control its sampling rate independently via a new MCCL_CTRAN_ALGO_PROFILING_SAMPLING_WEIGHT CVAR set on ctranConfig before ctranInit().

Changes:
- Add SamplingRegistry class (SamplingRegistry.h/.cc) with shouldTrace(opCount) method
- Add profilingSamplingWeight field to ctranConfig (default: NCCL_CTRAN_ALGO_PROFILING_SAMPLING_WEIGHT)
- Add MCCL_CTRAN_ALGO_PROFILING_SAMPLING_WEIGHT CVAR (int, default: 1)
- Profiler::initForEachColl() no longer takes samplingWeight parameter
- Update all 7 algorithm call sites to use simplified initForEachColl(opCount)
- MCCL sets profilingSamplingWeight on ctranConfig before ctranInit()
- Add SamplingRegistryTest with 5 test cases
- Update ProfilerTest to construct Profiler with config-based sampling weight

Differential Revision: D100706980
mlunar-meta added a commit to mlunar-meta/torchcomms that referenced this pull request Apr 14, 2026
…Count (meta-pytorch#2067)

Summary:

Add a `profilingSampleCount_` pointer on `CtranComm` that allows callers to control which counter the profiler uses for sampling decisions. When set, the profiler samples based on the pointed-to counter instead of opCount. When null (default), existing behavior is preserved — opCount is used.

MCCL uses this to sample based on a new `collectiveCount_` counter (incremented per allReduce call) rather than opCount, enabling independent sampling control.

Changes:
- Add `uint64_t* profilingSampleCount_` to CtranComm (nullptr = use opCount)
- Add `uint64_t collectiveCount_` to McclComm, incremented in allReduce
- Wire `profilingSampleCount_` to `collectiveCount_` in McclComm::finishInit
- Profiler::initForEachColl uses profilingSampleCount when set, else opCount
- Add AUTODEPS fix for profiler_test BUCK (ncclx-cvars dep)
- Add 2 test cases: override via profilingSampleCount, nullptr fallback to opCount

Differential Revision: D100730174
…Count (meta-pytorch#2067)

Summary:
Pull Request resolved: meta-pytorch#2067

Add a `profilingSampleCount_` pointer on `CtranComm` that allows callers to control which counter the profiler uses for sampling decisions. When set, the profiler samples based on the pointed-to counter instead of opCount. When null (default), existing behavior is preserved — opCount is used.

MCCL uses this to sample based on a new `collectiveCount_` counter (incremented per allReduce call) rather than opCount, enabling independent sampling control.

Changes:
- Add `uint64_t* profilingSampleCount_` to CtranComm (nullptr = use opCount)
- Add `uint64_t collectiveCount_` to McclComm, incremented in allReduce
- Wire `profilingSampleCount_` to `collectiveCount_` in McclComm::finishInit
- Profiler::initForEachColl uses profilingSampleCount when set, else opCount
- Add AUTODEPS fix for profiler_test BUCK (ncclx-cvars dep)
- Add 2 test cases: override via profilingSampleCount, nullptr fallback to opCount

Differential Revision: D100730174
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant