Skip to content

Patch readline-import issue which causes VLLMGenerator hang - #3950

Merged
pzhan9 merged 3 commits into
pytorch:mainfrom
pzhan9:sigttou_fix
Jul 21, 2026
Merged

pzhan9 merged 3 commits into
pytorch:mainfrom
pzhan9:sigttou_fix

Conversation

@pzhan9

@pzhan9 pzhan9 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

The reason is explained in the in-line comments. This issue seems to be caused by a recent change in vllm, which introduces tilelang import, and subsequently triggers the import chain.

Note that this is not a monarch bug. Although one can argue if monarch spawns the ProcMesh in a new session, i.e. change setpgid to setsid, readline-import's behavior will be tolerant, but the Monarch team does not think simply tolerating such behavior justifies an critical infra change on the Monarch side. More importantly, the Monarch side is not sure whether it might require sharing session in the future, and it does not want to lose that option too casually. As a result, the Monarch prefers to workaround it on the user side, especially given the workaround is reasonably small. cc: @shayne-fletcher

In addition, add torchvision to README's installation instruction since it is required by vllm recently.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 20, 2026
Comment on lines +82 to +84
# vLLM -> tilelang -> tvm -> tvm's base.py -> import readline
# https://github.com/vllm-project/vllm/blob/b23bd73f540175f9e117eaee5029cd7d8df63964/vllm/utils/jit_monitor.py#L451
# https://github.com/tile-ai/tvm/blob/28a0d34420d2fa9bc71fc891445a3f1396fca759/python/tvm/base.py#L71

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My read is monarch is not compatiable with vllm. It should be either fixed in monarch or vllm, not user side? And this patch is hacking and hard to understand from RL infra user level

@pzhan9 pzhan9 Jul 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The culprit is readline. For some versions' readline, you cannot import it in a background process. This is an old problem. The oldest one I found was in 2012: python/cpython#59097

It also bit torch.distrubuted recently: pytorch/pytorch#159645. In that issue, the user reported that they could not run torch.distributed in a background process. This issue is very similar to what we saw here: vllm does import readline unintentionally, which blocks vllm from being used in a background process.

Monarch is being caught in the crossfire, because it uses background processes to run its actors. But using background process is not wrong. That is why we do not want to make a big change to Monarch just to cater this decade old issue.

Can we patch it in vllm, or maybe its dependencies, e.g. tvm? It is possible. I have not looked into that. But even if that is technically possible, it might take a while to resolve, so we still need some patch here to unblock.

@wwwjn wwwjn Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand it's easier to fix from user side, but I still think it should not be a user side fix. I guess a more clear fix path is landing this temporary fix, and raise an github issue in tvm (even a direct PR in tvm)

background process is not wrong

Choosing background process as the design for monarch sounds correct, but the error is originally caused by vllm upstream. Just want to fix at the right place

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I submitted a PR and opened an issue as well in case they prefer a different fix:

tile-ai/tvm#55
tile-ai/tvm#54

4. Install PyTorch nightly, pre-built vllm wheel (based on PyTorch nightly version), and torchcomms nightly.
4. Install PyTorch and torchvision nightlies, pre-built vllm wheel (based on PyTorch nightly version), and torchcomms nightly.

`torchvision` is only needed because the current vllm nightly imports it during kernel warmup; TorchTitan RL does not otherwise require it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why wouldn't vllm nightly wheel already depend on this and automatically install?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vllm is installed from the wheel, and torchvision is not in the wheel's Requires-Dist. Probably that is because vllm excludes it here (disclaim: I have not checked e2e):

https://github.com/vllm-project/vllm/blob/9dd62d80abad5d2ebeb0a4a60ad005a23c23d0e9/use_existing_torch.py#L44

Comment thread torchtitan/experiments/rl/train.py Outdated
Comment thread torchtitan/experiments/rl/train.py
@pzhan9
pzhan9 merged commit cadbf37 into pytorch:main Jul 21, 2026
8 of 10 checks passed
@pzhan9
pzhan9 deleted the sigttou_fix branch July 21, 2026 00:43
saforem2 pushed a commit to saforem2/torchtitan that referenced this pull request Jul 21, 2026
…3950)

The reason is explained in the in-line comments. This issue seems to be
caused by a [recent change in
vllm](vllm-project/vllm#46718), which introduces
tilelang import, and subsequently triggers the import chain.

Note that this is not a monarch bug. Although one can argue if monarch
spawns the ProcMesh in a new session, [i.e. change `setpgid` to
`setsid`](https://github.com/meta-pytorch/monarch/blob/a4af2fe08e8fd7fceac736089631bacf0baf5c7b/hyperactor_mesh/src/proc_launcher/native.rs#L355),
readline-import's behavior will be tolerant, but the Monarch team does
not think simply tolerating such behavior justifies an critical infra
change on the Monarch side. More importantly, the Monarch side is not
sure whether it might require sharing session in the future, and it does
not want to lose that option too casually. As a result, the Monarch
prefers to workaround it on the user side, especially given the
workaround is reasonably small. cc: @shayne-fletcher

In addition, add `torchvision` to README's installation instruction
since it is required by vllm recently.
saforem2 added a commit to saforem2/torchtitan that referenced this pull request Jul 21, 2026
mreso added a commit to mreso/torchtitan that referenced this pull request Jul 21, 2026
Absorbs 4 upstream commits (checkpoint load/resume clarify pytorch#3732, override kwargs
from CLI+config pytorch#3894, [spmd_types] VarlenAttention un-hardcode pytorch#3937, VLLMGenerator
readline hang patch pytorch#3950). No conflicts; spmd_types regression verified -- GQA MoE
TP+EP+typecheck (12.48->6.82) and DSA GLM-5 TP=2 (12.53->6.82) both clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants