MCPcopy Create free account
hub / github.com/twitter/the-algorithm-ml / forward

Method forward

model.py:29–50  ·  view source on GitHub ↗

Runs model forward and calculates loss according to given loss_fn. NOTE: The input signature here needs to be a Pipelineable object for prefetching purposes during training using torchrec's pipeline. However the underlying model signature needs to be exportable to onnx, requiring g

(self, batch: "RecapBatch")

Source from the content-addressed store, hash-verified

27 self.loss_fn = loss_fn
28
29 def forward(self, batch: "RecapBatch"): # type: ignore[name-defined]
30 """Runs model forward and calculates loss according to given loss_fn.
31
32 NOTE: The input signature here needs to be a Pipelineable object for
33 prefetching purposes during training using torchrec's pipeline. However
34 the underlying model signature needs to be exportable to onnx, requiring
35 generic python types. see https://pytorch.org/docs/stable/onnx.html#types.
36
37 """
38 outputs = self.model(batch)
39 losses = self.loss_fn(outputs["logits"], batch.labels.float(), batch.weights.float())
40
41 outputs.update(
42 {
43 "loss": losses,
44 "labels": batch.labels,
45 "weights": batch.weights,
46 }
47 )
48
49 # Allow multiple losses.
50 return losses, outputs
51
52
53def maybe_shard_model(

Callers

nothing calls this directly

Calls 1

updateMethod · 0.45

Tested by

no test coverage detected