Function serve_model

  • Serve a model with forward and optimization endpoints.

    Remarks

    This server is to be used with network.remote_model. The function does not return.

    Example

    const weight = sm.randn([128, 128]).requireGrad()
    function model(input) {
    return input.matmul(weight).maximum(sm.scalar(0))
    }

    function optimize(differentiated_tensors) {
    for (let t of differentiated_tensors) {
    t.update(t.add(t.grad.mul(sm.scalar(1e-3))))
    }
    }
    sm.network.serve_model(model, optimize)

    Additional functions can also be served (as in network.serve):

    function extraMethod() {
    return sm.identity(7)
    }
    sm.network.serve_model(model, sm.optim.sgd, {port:3000}, {
    ident: extraMethod
    })

    Parameters

    • fn: ((t: Tensor) => Tensor | Promise<Tensor>)

      A function that will run on forward calls

    • grad_update: OptimizerFn

      A function that will run on backward calls, with a list of differentiated tensors passed in

    • options: ServeOptions

      An optional list of options passed to the underlying Bun.serve call

    • Optional req_map: Record<string, ((...args: unknown[]) => unknown)>

      An optional map of additional handlers passed to the underlying network.serve call

    Returns void

Generated using TypeDoc