# FSDP2 support for PyTorch ray train

**URL:** https://discuss.ray.io/t/fsdp2-support-for-pytorch-ray-train/21644
**Category:** Ray Train
**Created:** [January 29, 2025, 7:58pm UTC](https://discuss.ray.io/t/fsdp2-support-for-pytorch-ray-train/21644 "2025-01-29T19:58:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![navmarri1](https://avatars.discourse-cdn.com/v4/letter/n/9de0a6/32.png) [@navmarri1](https://discuss.ray.io/u/navmarri1)
#### Post date: [January 29, 2025, 7:58pm UTC](https://discuss.ray.io/t/fsdp2-support-for-pytorch-ray-train/21644/1 "2025-01-29T19:58:08Z")

</div>

Hi, I am trying to have support for fsdp2 in ray train. It seems like the `parallel_strategy` param in `prepare_model()` has only option for `ddp` and `fsdp`. Is there a way to wrap the model around `fsdp2`?

---

<div class="post-metadata">

### Author: ![SumanthRH](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sumanthrh/32/7430_2.png) [@SumanthRH](https://discuss.ray.io/u/SumanthRH)
#### Post date: [January 31, 2025, 7:35pm UTC](https://discuss.ray.io/t/fsdp2-support-for-pytorch-ray-train/21644/2 "2025-01-31T19:35:15Z")

</div>

Hi! Since `torch` made `fsdp2` a public API only in torch 2.6 (released a week ago), we do not have support for FSDP2 in `ray.train.prepare_model` yet.

However, ray train is highly flexible and thus you can manually wrap `model` in FSDP2 until then:

```auto
- model = ray.train.prepare_model(model)
+ from torch.distributed.fsdp import fully_shard # torch >= 2.6
+ # fill in any fsdp_kwargs below. 
+ # fsdp2 is in-place, uses current `device` 
+ fully_shard(model, **fsdp_kwargs) 

```

This is the simplest example where only the entire model is wrapped with `fully_shard` . For more on fsdp2 api usage you can refer to the API docs: [torch.distributed.fsdp.fully\_shard — PyTorch 2.6 documentation](https://pytorch.org/docs/stable/distributed.fsdp.fully_shard.html) and the RFC: [[RFC] Per-Parameter-Sharding FSDP · Issue #114299 · pytorch/pytorch · GitHub](https://github.com/pytorch/pytorch/issues/114299)
