Skip to content

install debug expert token counters on nvfp4 moe test script#4322

Merged
vkuzo merged 53 commits intomainfrom
gh/vkuzo/258/head
Apr 24, 2026
Merged

install debug expert token counters on nvfp4 moe test script#4322
vkuzo merged 53 commits intomainfrom
gh/vkuzo/258/head

Conversation

@vkuzo
Copy link
Copy Markdown
Contributor

@vkuzo vkuzo commented Apr 23, 2026

Summary:

Add expert counters on HF olmoe model to get token-expert counts.
This helps understand how much calibration is needed to get
a reasonable amount for tokens per expert for PTQ algorithms.

For this specific model, seems that calibrating on c4 will quickly hit
all the experts:

(pt_nightly) dev@gpu-dev-fef610c2:~/ao (20260420_gptq_nvfp4)$ time python scripts/prototype/test_nvfp4_moe.py --recipe=bf16 --calibrate_on_c4 --num_calibration_samples 1
...
=== Global expert utilization summary ===
experts with <= 0 tokens: 4/1024 (0.4%)
experts with <= 10 tokens: 60/1024 (5.9%)
experts with <= 20 tokens: 136/1024 (13.3%)
experts with <= 30 tokens: 220/1024 (21.5%)
experts with <= 40 tokens: 322/1024 (31.4%)
experts with <= 50 tokens: 404/1024 (39.5%)
experts with <= 60 tokens: 507/1024 (49.5%)
experts with <= 70 tokens: 612/1024 (59.8%)
experts with <= 80 tokens: 706/1024 (68.9%)
experts with <= 90 tokens: 799/1024 (78.0%)
experts with <= 100 tokens: 878/1024 (85.7%)
experts with <= 110 tokens: 923/1024 (90.1%)
experts with <= 120 tokens: 958/1024 (93.6%)

// min number for at least one token per expert
(pt_nightly) dev@gpu-dev-fef610c2:~/ao (20260420_gptq_nvfp4)$ time python scripts/prototype/test_nvfp4_moe.py --recipe=bf16 --calibrate_on_c4 --num_calibration_samples 3
...
=== Global expert utilization summary ===
experts with <= 0 tokens: 0/1024 (0.0%)
experts with <= 10 tokens: 1/1024 (0.1%)
experts with <= 20 tokens: 9/1024 (0.9%)
experts with <= 30 tokens: 22/1024 (2.1%)
experts with <= 40 tokens: 32/1024 (3.1%)
experts with <= 50 tokens: 49/1024 (4.8%)
experts with <= 60 tokens: 60/1024 (5.9%)
experts with <= 70 tokens: 69/1024 (6.7%)
experts with <= 80 tokens: 81/1024 (7.9%)
experts with <= 90 tokens: 88/1024 (8.6%)
experts with <= 100 tokens: 115/1024 (11.2%)
experts with <= 110 tokens: 130/1024 (12.7%)
experts with <= 120 tokens: 149/1024 (14.6%)

// resonable default
(pt_nightly) dev@gpu-dev-fef610c2:~/ao (20260420_gptq_nvfp4)$ time python scripts/prototype/test_nvfp4_moe.py --recipe=bf16 --calibrate_on_c4 --num_calibration_samples 128
...
=== Global expert utilization summary ===
experts with <= 0 tokens: 0/1024 (0.0%)
experts with <= 10 tokens: 0/1024 (0.0%)
experts with <= 20 tokens: 0/1024 (0.0%)
experts with <= 30 tokens: 0/1024 (0.0%)
experts with <= 40 tokens: 0/1024 (0.0%)
experts with <= 50 tokens: 0/1024 (0.0%)
experts with <= 60 tokens: 0/1024 (0.0%)
experts with <= 70 tokens: 0/1024 (0.0%)
experts with <= 80 tokens: 0/1024 (0.0%)
experts with <= 90 tokens: 0/1024 (0.0%)
experts with <= 100 tokens: 0/1024 (0.0%)
experts with <= 110 tokens: 0/1024 (0.0%)
experts with <= 120 tokens: 0/1024 (0.0%)

90% clauded

Test Plan:

vkuzo added 30 commits April 20, 2026 20:52
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@vkuzo
Copy link
Copy Markdown
Contributor Author

vkuzo commented Apr 23, 2026

@vkuzo vkuzo requested a review from jerryzh168 as a code owner April 23, 2026 17:21
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 23, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4322

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 1 New Failure

As of commit f8d1861 with merge base 67a78e5 (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 23, 2026
@vkuzo vkuzo added the module: not user facing Use this tag if you don't want this PR to show up in release notes label Apr 23, 2026
vkuzo added 4 commits April 23, 2026 18:44
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Apr 23, 2026
Summary:

Add expert counters on HF olmoe model to get token-expert counts.
This helps understand how much calibration is needed to get
a reasonable amount for tokens per expert for PTQ algorithms.

For this specific model, seems that calibrating on c4 will quickly hit
all the experts:

```
(pt_nightly) dev@gpu-dev-fef610c2:~/ao (20260420_gptq_nvfp4)$ time python scripts/prototype/test_nvfp4_moe.py --recipe=bf16 --calibrate_on_c4 --num_calibration_samples 1
...
=== Global expert utilization summary ===
experts with <= 0 tokens: 4/1024 (0.4%)
experts with <= 10 tokens: 60/1024 (5.9%)
experts with <= 20 tokens: 136/1024 (13.3%)
experts with <= 30 tokens: 220/1024 (21.5%)
experts with <= 40 tokens: 322/1024 (31.4%)
experts with <= 50 tokens: 404/1024 (39.5%)
experts with <= 60 tokens: 507/1024 (49.5%)
experts with <= 70 tokens: 612/1024 (59.8%)
experts with <= 80 tokens: 706/1024 (68.9%)
experts with <= 90 tokens: 799/1024 (78.0%)
experts with <= 100 tokens: 878/1024 (85.7%)
experts with <= 110 tokens: 923/1024 (90.1%)
experts with <= 120 tokens: 958/1024 (93.6%)

// min number for at least one token per expert
(pt_nightly) dev@gpu-dev-fef610c2:~/ao (20260420_gptq_nvfp4)$ time python scripts/prototype/test_nvfp4_moe.py --recipe=bf16 --calibrate_on_c4 --num_calibration_samples 3
...
=== Global expert utilization summary ===
experts with <= 0 tokens: 0/1024 (0.0%)
experts with <= 10 tokens: 1/1024 (0.1%)
experts with <= 20 tokens: 9/1024 (0.9%)
experts with <= 30 tokens: 22/1024 (2.1%)
experts with <= 40 tokens: 32/1024 (3.1%)
experts with <= 50 tokens: 49/1024 (4.8%)
experts with <= 60 tokens: 60/1024 (5.9%)
experts with <= 70 tokens: 69/1024 (6.7%)
experts with <= 80 tokens: 81/1024 (7.9%)
experts with <= 90 tokens: 88/1024 (8.6%)
experts with <= 100 tokens: 115/1024 (11.2%)
experts with <= 110 tokens: 130/1024 (12.7%)
experts with <= 120 tokens: 149/1024 (14.6%)

// resonable default
(pt_nightly) dev@gpu-dev-fef610c2:~/ao (20260420_gptq_nvfp4)$ time python scripts/prototype/test_nvfp4_moe.py --recipe=bf16 --calibrate_on_c4 --num_calibration_samples 128
...
=== Global expert utilization summary ===
experts with <= 0 tokens: 0/1024 (0.0%)
experts with <= 10 tokens: 0/1024 (0.0%)
experts with <= 20 tokens: 0/1024 (0.0%)
experts with <= 30 tokens: 0/1024 (0.0%)
experts with <= 40 tokens: 0/1024 (0.0%)
experts with <= 50 tokens: 0/1024 (0.0%)
experts with <= 60 tokens: 0/1024 (0.0%)
experts with <= 70 tokens: 0/1024 (0.0%)
experts with <= 80 tokens: 0/1024 (0.0%)
experts with <= 90 tokens: 0/1024 (0.0%)
experts with <= 100 tokens: 0/1024 (0.0%)
experts with <= 110 tokens: 0/1024 (0.0%)
experts with <= 120 tokens: 0/1024 (0.0%)
```

90% clauded

Test Plan:
ghstack-source-id: 4860e17
ghstack-comment-id: 4306401628
Pull-Request: #4322
vkuzo added 3 commits April 23, 2026 18:45
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Apr 23, 2026
Summary:

Add expert counters on HF olmoe model to get token-expert counts.
This helps understand how much calibration is needed to get
a reasonable amount for tokens per expert for PTQ algorithms.

For this specific model, seems that calibrating on c4 will quickly hit
all the experts:

```
(pt_nightly) dev@gpu-dev-fef610c2:~/ao (20260420_gptq_nvfp4)$ time python scripts/prototype/test_nvfp4_moe.py --recipe=bf16 --calibrate_on_c4 --num_calibration_samples 1
...
=== Global expert utilization summary ===
experts with <= 0 tokens: 4/1024 (0.4%)
experts with <= 10 tokens: 60/1024 (5.9%)
experts with <= 20 tokens: 136/1024 (13.3%)
experts with <= 30 tokens: 220/1024 (21.5%)
experts with <= 40 tokens: 322/1024 (31.4%)
experts with <= 50 tokens: 404/1024 (39.5%)
experts with <= 60 tokens: 507/1024 (49.5%)
experts with <= 70 tokens: 612/1024 (59.8%)
experts with <= 80 tokens: 706/1024 (68.9%)
experts with <= 90 tokens: 799/1024 (78.0%)
experts with <= 100 tokens: 878/1024 (85.7%)
experts with <= 110 tokens: 923/1024 (90.1%)
experts with <= 120 tokens: 958/1024 (93.6%)

// min number for at least one token per expert
(pt_nightly) dev@gpu-dev-fef610c2:~/ao (20260420_gptq_nvfp4)$ time python scripts/prototype/test_nvfp4_moe.py --recipe=bf16 --calibrate_on_c4 --num_calibration_samples 3
...
=== Global expert utilization summary ===
experts with <= 0 tokens: 0/1024 (0.0%)
experts with <= 10 tokens: 1/1024 (0.1%)
experts with <= 20 tokens: 9/1024 (0.9%)
experts with <= 30 tokens: 22/1024 (2.1%)
experts with <= 40 tokens: 32/1024 (3.1%)
experts with <= 50 tokens: 49/1024 (4.8%)
experts with <= 60 tokens: 60/1024 (5.9%)
experts with <= 70 tokens: 69/1024 (6.7%)
experts with <= 80 tokens: 81/1024 (7.9%)
experts with <= 90 tokens: 88/1024 (8.6%)
experts with <= 100 tokens: 115/1024 (11.2%)
experts with <= 110 tokens: 130/1024 (12.7%)
experts with <= 120 tokens: 149/1024 (14.6%)

// resonable default
(pt_nightly) dev@gpu-dev-fef610c2:~/ao (20260420_gptq_nvfp4)$ time python scripts/prototype/test_nvfp4_moe.py --recipe=bf16 --calibrate_on_c4 --num_calibration_samples 128
...
=== Global expert utilization summary ===
experts with <= 0 tokens: 0/1024 (0.0%)
experts with <= 10 tokens: 0/1024 (0.0%)
experts with <= 20 tokens: 0/1024 (0.0%)
experts with <= 30 tokens: 0/1024 (0.0%)
experts with <= 40 tokens: 0/1024 (0.0%)
experts with <= 50 tokens: 0/1024 (0.0%)
experts with <= 60 tokens: 0/1024 (0.0%)
experts with <= 70 tokens: 0/1024 (0.0%)
experts with <= 80 tokens: 0/1024 (0.0%)
experts with <= 90 tokens: 0/1024 (0.0%)
experts with <= 100 tokens: 0/1024 (0.0%)
experts with <= 110 tokens: 0/1024 (0.0%)
experts with <= 120 tokens: 0/1024 (0.0%)
```

90% clauded

Test Plan:
ghstack-source-id: 4860e17
ghstack-comment-id: 4306401628
Pull-Request: #4322
vkuzo added 2 commits April 23, 2026 18:46
[ghstack-poisoned]
[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Apr 23, 2026
Summary:

Add expert counters on HF olmoe model to get token-expert counts.
This helps understand how much calibration is needed to get
a reasonable amount for tokens per expert for PTQ algorithms.

For this specific model, seems that calibrating on c4 will quickly hit
all the experts:

```
(pt_nightly) dev@gpu-dev-fef610c2:~/ao (20260420_gptq_nvfp4)$ time python scripts/prototype/test_nvfp4_moe.py --recipe=bf16 --calibrate_on_c4 --num_calibration_samples 1
...
=== Global expert utilization summary ===
experts with <= 0 tokens: 4/1024 (0.4%)
experts with <= 10 tokens: 60/1024 (5.9%)
experts with <= 20 tokens: 136/1024 (13.3%)
experts with <= 30 tokens: 220/1024 (21.5%)
experts with <= 40 tokens: 322/1024 (31.4%)
experts with <= 50 tokens: 404/1024 (39.5%)
experts with <= 60 tokens: 507/1024 (49.5%)
experts with <= 70 tokens: 612/1024 (59.8%)
experts with <= 80 tokens: 706/1024 (68.9%)
experts with <= 90 tokens: 799/1024 (78.0%)
experts with <= 100 tokens: 878/1024 (85.7%)
experts with <= 110 tokens: 923/1024 (90.1%)
experts with <= 120 tokens: 958/1024 (93.6%)

// min number for at least one token per expert
(pt_nightly) dev@gpu-dev-fef610c2:~/ao (20260420_gptq_nvfp4)$ time python scripts/prototype/test_nvfp4_moe.py --recipe=bf16 --calibrate_on_c4 --num_calibration_samples 3
...
=== Global expert utilization summary ===
experts with <= 0 tokens: 0/1024 (0.0%)
experts with <= 10 tokens: 1/1024 (0.1%)
experts with <= 20 tokens: 9/1024 (0.9%)
experts with <= 30 tokens: 22/1024 (2.1%)
experts with <= 40 tokens: 32/1024 (3.1%)
experts with <= 50 tokens: 49/1024 (4.8%)
experts with <= 60 tokens: 60/1024 (5.9%)
experts with <= 70 tokens: 69/1024 (6.7%)
experts with <= 80 tokens: 81/1024 (7.9%)
experts with <= 90 tokens: 88/1024 (8.6%)
experts with <= 100 tokens: 115/1024 (11.2%)
experts with <= 110 tokens: 130/1024 (12.7%)
experts with <= 120 tokens: 149/1024 (14.6%)

// resonable default
(pt_nightly) dev@gpu-dev-fef610c2:~/ao (20260420_gptq_nvfp4)$ time python scripts/prototype/test_nvfp4_moe.py --recipe=bf16 --calibrate_on_c4 --num_calibration_samples 128
...
=== Global expert utilization summary ===
experts with <= 0 tokens: 0/1024 (0.0%)
experts with <= 10 tokens: 0/1024 (0.0%)
experts with <= 20 tokens: 0/1024 (0.0%)
experts with <= 30 tokens: 0/1024 (0.0%)
experts with <= 40 tokens: 0/1024 (0.0%)
experts with <= 50 tokens: 0/1024 (0.0%)
experts with <= 60 tokens: 0/1024 (0.0%)
experts with <= 70 tokens: 0/1024 (0.0%)
experts with <= 80 tokens: 0/1024 (0.0%)
experts with <= 90 tokens: 0/1024 (0.0%)
experts with <= 100 tokens: 0/1024 (0.0%)
experts with <= 110 tokens: 0/1024 (0.0%)
experts with <= 120 tokens: 0/1024 (0.0%)
```

90% clauded

Test Plan:
ghstack-source-id: 4860e17
ghstack-comment-id: 4306401628
Pull-Request: #4322
[ghstack-poisoned]
@vkuzo vkuzo changed the base branch from gh/vkuzo/257/head to main April 23, 2026 18:47
vkuzo added a commit that referenced this pull request Apr 23, 2026
Summary:

Add expert counters on HF olmoe model to get token-expert counts.
This helps understand how much calibration is needed to get
a reasonable amount for tokens per expert for PTQ algorithms.

For this specific model, seems that calibrating on c4 will quickly hit
all the experts:

```
(pt_nightly) dev@gpu-dev-fef610c2:~/ao (20260420_gptq_nvfp4)$ time python scripts/prototype/test_nvfp4_moe.py --recipe=bf16 --calibrate_on_c4 --num_calibration_samples 1
...
=== Global expert utilization summary ===
experts with <= 0 tokens: 4/1024 (0.4%)
experts with <= 10 tokens: 60/1024 (5.9%)
experts with <= 20 tokens: 136/1024 (13.3%)
experts with <= 30 tokens: 220/1024 (21.5%)
experts with <= 40 tokens: 322/1024 (31.4%)
experts with <= 50 tokens: 404/1024 (39.5%)
experts with <= 60 tokens: 507/1024 (49.5%)
experts with <= 70 tokens: 612/1024 (59.8%)
experts with <= 80 tokens: 706/1024 (68.9%)
experts with <= 90 tokens: 799/1024 (78.0%)
experts with <= 100 tokens: 878/1024 (85.7%)
experts with <= 110 tokens: 923/1024 (90.1%)
experts with <= 120 tokens: 958/1024 (93.6%)

// min number for at least one token per expert
(pt_nightly) dev@gpu-dev-fef610c2:~/ao (20260420_gptq_nvfp4)$ time python scripts/prototype/test_nvfp4_moe.py --recipe=bf16 --calibrate_on_c4 --num_calibration_samples 3
...
=== Global expert utilization summary ===
experts with <= 0 tokens: 0/1024 (0.0%)
experts with <= 10 tokens: 1/1024 (0.1%)
experts with <= 20 tokens: 9/1024 (0.9%)
experts with <= 30 tokens: 22/1024 (2.1%)
experts with <= 40 tokens: 32/1024 (3.1%)
experts with <= 50 tokens: 49/1024 (4.8%)
experts with <= 60 tokens: 60/1024 (5.9%)
experts with <= 70 tokens: 69/1024 (6.7%)
experts with <= 80 tokens: 81/1024 (7.9%)
experts with <= 90 tokens: 88/1024 (8.6%)
experts with <= 100 tokens: 115/1024 (11.2%)
experts with <= 110 tokens: 130/1024 (12.7%)
experts with <= 120 tokens: 149/1024 (14.6%)

// resonable default
(pt_nightly) dev@gpu-dev-fef610c2:~/ao (20260420_gptq_nvfp4)$ time python scripts/prototype/test_nvfp4_moe.py --recipe=bf16 --calibrate_on_c4 --num_calibration_samples 128
...
=== Global expert utilization summary ===
experts with <= 0 tokens: 0/1024 (0.0%)
experts with <= 10 tokens: 0/1024 (0.0%)
experts with <= 20 tokens: 0/1024 (0.0%)
experts with <= 30 tokens: 0/1024 (0.0%)
experts with <= 40 tokens: 0/1024 (0.0%)
experts with <= 50 tokens: 0/1024 (0.0%)
experts with <= 60 tokens: 0/1024 (0.0%)
experts with <= 70 tokens: 0/1024 (0.0%)
experts with <= 80 tokens: 0/1024 (0.0%)
experts with <= 90 tokens: 0/1024 (0.0%)
experts with <= 100 tokens: 0/1024 (0.0%)
experts with <= 110 tokens: 0/1024 (0.0%)
experts with <= 120 tokens: 0/1024 (0.0%)
```

90% clauded

Test Plan:
ghstack-source-id: 4860e17
ghstack-comment-id: 4306401628
Pull-Request: #4322
@vkuzo vkuzo merged commit 899fea2 into main Apr 24, 2026
50 of 53 checks passed
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 Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: not user facing Use this tag if you don't want this PR to show up in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants