trl
trl copied to clipboard
FSDP2 vLLM weight sync crashes with ignored parameters
Reproduction
import os
import tempfile
from types import SimpleNamespace
import torch
import torch.nn as nn
from torch.distributed._composable.fsdp import fully_shard
from trl.generation.vllm_generation import VLLMGeneration
class TinyModel(nn.Module):
def __init__(self):
super().__init__()
self.emb = nn.Embedding(50, 8)
self.linear = nn.Linear(8, 8)
self.head = nn.Linear(8, 50)
store_dir = tempfile.mkdtemp()
torch.distributed.init_process_group(
"gloo",
rank=0,
world_size=1,
store=torch.distributed.FileStore(os.path.join(store_dir, "store"), 1),
)
try:
model = TinyModel()
# Simulates an ignored module configured through FSDP2/Accelerate.
ignored_params = set(model.head.parameters())
fully_shard(model, ignored_params=ignored_params)
for name, value in model.state_dict().items():
print(name, type(value).__name__, hasattr(value, "full_tensor"))
# Instantiate the real TRL backend without starting vLLM.
sync = object.__new__(VLLMGeneration)
sync.accelerator = SimpleNamespace(device=torch.device("cpu"))
sync.mode = "colocate"
sync._push_param_to_vllm = lambda name, value: None
sync._sync_fsdp2_params_to_vllm(model)
finally:
torch.distributed.destroy_process_group() ...
outputs:
emb.weight DTensor True
linear.weight DTensor True
linear.bias DTensor True
head.weight Tensor False
head.bias Tensor False
Traceback (most recent call last):
File ".../trl/generation/vllm_generation.py", line 435, in _sync_fsdp2_params_to_vllm
param = param.full_tensor()
AttributeError: 'Tensor' object has no attribute 'full_tensor'
With FSDP2, parameters included in ignored_params remain regular torch.Tensor objects, while sharded parameters are DTensor objects.
VLLMGeneration._sync_fsdp2_params_to_vllm calls param.full_tensor() unconditionally for every value returned by
module.state_dict(). This crashes when the state dict reaches an ignored parameter.
The same logic exists in:
trl/generation/vllm_generation.py:435trl/experimental/online_dpo/online_dpo_trainer.py:757
Expected behavior is for ignored regular tensors to be synchronized without calling full_tensor(), or for the configuration to fail earlier with a clear error.
System Info
- Platform: Windows-11-10.0.26200-SP0
- Python version: 3.12.13
- TRL version: 1.10.0.dev0+3e72f8e
- PyTorch version: 2.13.0+cpu
- accelerator(s): cpu
- Transformers version: 5.14.1
- Accelerate version: 1.14.0
- Accelerate config: not found
- Datasets version: 5.0.1
- HF Hub version: 1.26.0
- bitsandbytes version: not installed
- DeepSpeed version: not installed
- Liger-Kernel version: not installed
- PEFT version: 0.20.0
- vLLM version: not installed
Checklist
- [x] I have checked that my issue isn't already filed (see open issues)
- [x] I have included my system information
- [x] Any code provided is minimal, complete, and reproducible (more on MREs)
- [x] Any code provided is properly formatted in code blocks, (no screenshot, more on code blocks)
- [x] Any traceback provided is complete