Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

09: Models

E0901

Model has no such field. m.name reads a field that the model doesn’t declare. The help suggests a field with a similar name.

dim D = 64

model Mlp:
    param w1: [D D] = normal(std=0.02)

fn f(m: Mlp, x: [b D]) -> [b D] = x @ m.w2

See Using models.

E0902

Invalid model field. A field’s type has ?k, has no shape, is a host scalar, a model, optimizer state or a Schedule; a param holds something other than floats or has a domain; a buffer has a domain other than a range, Index[V] or Mask; or the field’s name is init, a Python keyword, starts with _, or is an attribute of torch.nn.Module.

dim D = 64

model Counter:
    param count: [] i64 = zeros

See Fields.

E0903

Invalid field initializer. A field has no initializer, or one that isn’t zeros, ones, full, normal or uniform; its arguments are wrong (too many, unknown names, given twice, full without a value, a negative std, lo more than hi); normal or uniform fills a field that isn’t float; or the values it gives don’t fit the field’s domain.

dim D = 64

model Mlp:
    param w1: [D D] = gaussian(std=0.02)

See Initializers.

E0904

Value isn’t the expected model. A parameter or return type is a model, and the value is another model or a tensor. Models are matched by name.

dim D = 64

model A:
    param w: [D D] = zeros

model B:
    param w: [D D] = zeros

fn apply(m: A, x: [b D]) -> [b D] = x @ m.w

fn f(m: B, x: [b D]) -> [b D] = apply(m, x)

See Using models.