Repository navigation
Description
Describe the bug
CI test gpt_grpo_basic_function failed in job gpt/gpt_grpo_basic_function - latest.
Tag the @mcore-oncall to get oncall's attention to this issue.
This is a regression on main (any PR rebased on current main will inherit it). The proximate trigger is the automated dep bump commit e93755e13a (chore(beep boop π€): Bump (main) (2026-05-11)), which upgraded:
transformers4.57.6 β 5.8.0huggingface_hub0.36.2 β 1.14.0
In transformers 5.x, tokenizer.apply_chat_template(..., tokenize=True, tools=...) no longer returns a plain list[int] β it returns a BatchEncoding. The chat-completions endpoint passes that straight to client.add_request(prompt_tokens, ...) at megatron/core/inference/text_generation_server/dynamic_text_gen_server/endpoints/chat_completions.py:569, which feeds it to msgpack.packb at megatron/core/inference/inference_client.py:111. msgpack has no encoder for BatchEncoding, so every /chat/completions request 500s and the GRPO rollout pipeline fails.
Bisect evidence (against GitLab project 19378, ref: main):
| Pipeline | SHA | gpt_grpo_basic_function |
|---|---|---|
| 50856861 (May 10 14:55 UTC) | 5e31514165 |
success |
| 50916295 (May 11 06:09 UTC) | ad58411ddb |
failed (BatchEncoding) |
The only dependency-touching commit between those two SHAs is e93755e13a.
Failing run
| Field | Value |
|---|---|
| PR | #4723: build(deps): bump nvidia-modelopt to 0.43 |
| Run | 25673275359 |
| Job | gpt/gpt_grpo_basic_function - latest |
Error
ERROR:megatron.core.inference.text_generation_server.dynamic_text_gen_server.text_generation_server:Exception on request POST /chat/completions
Traceback (most recent call last):
File "/opt/venv/lib/python3.12/site-packages/quart/app.py", line 1500, in full_dispatch_request
result = await self.dispatch_request(request_context)
File "/opt/venv/lib/python3.12/site-packages/quart/app.py", line 1597, in dispatch_request
return await self.ensure_async(handler)(**request_.view_args)
File "/opt/megatron-lm/megatron/core/inference/text_generation_server/dynamic_text_gen_server/endpoints/chat_completions.py", line 569, in chat_completions
tasks = [client.add_request(prompt_tokens, sampling_params) for _ in range(n)]
File "/opt/megatron-lm/megatron/core/inference/inference_client.py", line 111, in add_request
payload_serialized = msgpack.packb(payload, use_bin_type=True)
File "/opt/venv/lib/python3.12/site-packages/msgpack/__init__.py", line 36, in packb
return Packer(**kwargs).pack(o)
File "msgpack/_packer.pyx", line 270, in msgpack._cmsgpack.Packer._pack
File "msgpack/_packer.pyx", line 257, in msgpack._cmsgpack.Packer._pack_inner
TypeError: can not serialize 'BatchEncoding' object
(Full log available via the job URL above.)
Likely fixes
Either of:
- Pin
transformers<5inpyproject.toml/uv.lockuntil the endpoint is updated. - Normalize the return value of
apply_chat_templateto a plain list atchat_completions.py:436and:482before passing toclient.add_requestβ e.g. coerce viaprompt_tokens["input_ids"]when aBatchEncodingis returned, or passreturn_dict=Falseexplicitly and unwrap any tensor returns.
Steps/Code to reproduce bug
Re-run the failing CI job linked above, or run the recipe locally inside the dev container:
bash ./tests/functional_tests/shell_test_utils/run_ci_test.sh \
TRAINING_SCRIPT_PATH=train_rl.py \
TRAINING_PARAMS_PATH=./tests/functional_tests/test_cases/gpt/gpt_grpo_basic_function/model_config.yamlAdditional context
Triaged automatically via /create-issue.
Activity
tdene commentedon May 11, 2026
Fix-in-progress at #4732
Currently running pipeline to verify fix.
ETA: ~3 hours.
balasaajay commentedon May 12, 2026
https://github.com/NVIDIA/Megatron-LM/actions/runs/25683875543/job/75459176159?pr=4682 failed with the same error.
balasaajay commentedon May 12, 2026
Additional failure mode observed: 1h job timeout (cancelled), not exit-code failure
Same root cause (
TypeError: can not serialize 'BatchEncoding' objectfrommsgpack.packbinchat_completionsβinference_client.add_request), but in this run the surface signal is a GitHub Actions step timeout / cancellation rather than a non-zero exit.Failing run
cancelled(exceeded the maximum execution time of 1h0m0s)Why it surfaces as a timeout here
TypeError: can not serialize 'BatchEncoding' objecttraceback starts at ~22:41:16(a few minutes into training) and repeats thousands of times β every/chat/completionsrequest returns 500.23:31:24.##[notice]β gpt_grpo_basic_function β PASSEDafter the cancel β that notice is not a real PASS, it's the cleanup echo running unconditionally.Log snippet (representative)
```
22:41:16 ERROR:megatron.core.inference.text_generation_server.dynamic_text_gen_server.text_generation_server:Exception on request POST /chat/completions
22:41:16 File "/opt/megatron-lm/megatron/core/inference/inference_client.py", line 111, in add_request
22:41:16 payload_serialized = msgpack.packb(payload, use_bin_type=True)
22:41:16 TypeError: can not serialize 'BatchEncoding' object
...
23:31:24 ##[error]The operation was canceled.
```
Mitigation applied for #4682
Disabled `gpt_grpo_basic_function` on the GitHub MR scope to unblock the PR while this issue is fixed:
```yaml
tests/test_utils/recipes/h100/gpt-grpo.yaml
products:
scope: [mr, mr-github-broken] # was [mr, mr-github]
platforms: [dgx_h100]
```
Re-enable once the BatchEncoding/msgpack fix lands.
ko3n1g commentedon May 26, 2026
Fixed in 86bf476 (PR #4732, merged 2026-05-12): "Support transfomers 5.x.x for text generation server" β coerces
BatchEncodingreturns fromapply_chat_templateto a plainlist[int]before passing toclient.add_requestinmegatron/core/inference/text_generation_server/dynamic_text_gen_server/endpoints/chat_completions.py. Thegpt_grpo_basic_functionscope is back to[mr, mr-github]ongithub/main. Closing as completed.