MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / forward

Method forward

deepspeed/runtime/sequence_parallel/ulysses_sp.py:989–1009  ·  view source on GitHub ↗
(
        ctx,
        fn,
        self,
        x,
        shards,
        compute_params,
    )

Source from the content-addressed store, hash-verified

987
988 @staticmethod
989 def forward(
990 ctx,
991 fn,
992 self,
993 x,
994 shards,
995 compute_params,
996 ) -> torch.Tensor:
997 ctx.fn = fn
998 ctx.self = self
999 ctx.shards = shards
1000 ctx.compute_params = [p for p in compute_params if p.requires_grad]
1001 ctx.save_for_backward(x)
1002
1003 # x.shape could be [bs, seqlen, hidden_size] or [seqlen, hidden_size] (moe experts)
1004 x_shards = list(torch.chunk(x, chunks=shards, dim=-2))
1005 with torch.no_grad():
1006 output_shards = [fn(self, x_shard) for x_shard in x_shards]
1007 output_unsharded = torch.cat(output_shards, dim=-2)
1008
1009 return output_unsharded
1010
1011 @staticmethod
1012 def backward(ctx, *grads) -> torch.Tensor:

Callers

nothing calls this directly

Calls 1

fnFunction · 0.85

Tested by

no test coverage detected