Skip to content

πŸ› CI failure: gpt_grpo_basic_function β€” BatchEncoding can't be msgpack-serialized after transformers 5.x bumpΒ #4726

Closed

Description

@ko3n1g

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:

  • transformers 4.57.6 β†’ 5.8.0
  • huggingface_hub 0.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:

  1. Pin transformers<5 in pyproject.toml/uv.lock until the endpoint is updated.
  2. Normalize the return value of apply_chat_template to a plain list at chat_completions.py:436 and :482 before passing to client.add_request β€” e.g. coerce via prompt_tokens["input_ids"] when a BatchEncoding is returned, or pass return_dict=False explicitly 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.yaml

Additional context

Triaged automatically via /create-issue.

Activity

  1. tdene commented on May 11, 2026

    @tdene
    Contributor

    Fix-in-progress at #4732

    Currently running pipeline to verify fix.

    ETA: ~3 hours.

  2. balasaajay commented on May 12, 2026

    @balasaajay
    Contributor
  3. balasaajay commented on May 12, 2026

    @balasaajay
    Contributor

    Additional failure mode observed: 1h job timeout (cancelled), not exit-code failure

    Same root cause (TypeError: can not serialize 'BatchEncoding' object from msgpack.packb in chat_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

    Field Value
    PR #4682: Update transformer-engine dependency to version 2.15.0
    Run 25683875543
    Job gpt/gpt_grpo_basic_function - latest
    Conclusion cancelled (exceeded the maximum execution time of 1h0m0s)

    Why it surfaces as a timeout here

    • The same TypeError: can not serialize 'BatchEncoding' object traceback starts at ~22:41:16 (a few minutes into training) and repeats thousands of times β€” every /chat/completions request returns 500.
    • The GRPO rollout loop has no successful responses to consume, so the test makes no progress and just hangs until the GitHub Actions step hits its 1h cap and is cancelled at 23:31:24.
    • The wrapper's always-runs cleanup step then prints a misleading ##[notice]βœ… gpt_grpo_basic_function β€” PASSED after 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

    • test_case: [gpt_grpo_basic_function]
      products:
      • environment: [dev]
        scope: [mr, mr-github-broken] # was [mr, mr-github]
        platforms: [dgx_h100]
        ```

    Re-enable once the BatchEncoding/msgpack fix lands.

  4. ko3n1g commented on May 26, 2026

    @ko3n1g
    ContributorAuthor

    Fixed in 86bf476 (PR #4732, merged 2026-05-12): "Support transfomers 5.x.x for text generation server" β€” coerces BatchEncoding returns from apply_chat_template to a plain list[int] before passing to client.add_request in megatron/core/inference/text_generation_server/dynamic_text_gen_server/endpoints/chat_completions.py. The gpt_grpo_basic_function scope is back to [mr, mr-github] on github/main. Closing as completed.

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions