borch

Learn · 3

Modules

nn.Module holds parameters and knows how to run forward. The names are torch's; the one difference is that you call it with model.call(x), because JavaScript cannot call an object.

A layer on its own

nn.Linear(in, out) stores weight as (out, in) — the same layout as torch, so a checkpoint moves across without transposing.

Stacking

nn.Sequential chains modules. parameters() collects every tensor the optimizer should touch — if a parameter is missing from that list, training runs and that layer simply never learns, with no error.

Writing your own

Extend nn.Module and implement forward. Parameters you create yourself must be claimed, otherwise they do not appear in parameters() — the failure is silent, so the base class makes you say it.

Losses

Losses live in the same namespace and are called the same way. CrossEntropyLoss takes logits and int64 targets, exactly as torch does — not one-hot vectors.