Model

public class Model

A model is a base class for stateful operations on a dynamic graph. It can be use to construct computations statically, thus, more efficient.

  • IO

    A IO class represent the abstract input / output for a model. It can correspond to one or more tensors when the model is materialized.

    See more

    Declaration

    Swift

    public class IO
  • Whether the existing model is for testing or training.

    Declaration

    Swift

    public var isTest: Bool
  • Declaration

    Swift

    public let cModel: OpaquePointer
  • Declaration

    Swift

    @inlinable
    public func callAsFunction(_ inputs: IO...) -> IO
  • Declaration

    Swift

    @inlinable
    public func callAsFunction(_ inputs: [IO]) -> IO
  • Declaration

    Swift

    public final class Parameters : IO
    extension Model.Parameters: DynamicGraph_AnyParameters
  • Abstract representation of the stateful components from the model.

    Declaration

    Swift

    public var parameters: Parameters { get }
  • Declaration

    Swift

    public enum ParametersType
  • Broadly speaking, you can have two types of parameters, weight and bias. You can get them in abstract fashion with this method.

    Declaration

    Swift

    public func parameters(for type: ParametersType) -> Parameters

    Parameters

    type

    Whether it is weight or bias.

    Return Value

    An abstract representation of parameters.

  • Declaration

    Swift

    public func callAsFunction<T: DynamicGraph.AnyTensorGroup>(
      inputs firstInput: T, _ restInputs: [DynamicGraph_Any], streamContext: StreamContext? = nil
    ) -> [T.AnyTensor]
  • Declaration

    Swift

    public func callAsFunction<T: DynamicGraph.AnyTensorGroup>(
      inputs firstInput: T, _ restInputs: DynamicGraph_Any..., streamContext: StreamContext? = nil
    ) -> [T.AnyTensor]
  • Make a copy of the model. This won’t copy over the parameters. If you want, you need to copy parameters over explicitly.

    Declaration

    Swift

    public func copied() -> Self
  • Compile a model with the given inputs without executing it. After this, you can load parameters from the store.

    Declaration

    Swift

    public func compile(inputs: DynamicGraph_Any...)
  • You can compose a new model from old models when applying IO on them.

    Declaration

    Swift

    public convenience init(_ inputs: [IO], _ outputs: [IO], name: String = "")

    Parameters

    inputs

    The input IOs for the new model, usually it is some set of Input objects.

    outputs

    The output IOs for the new model, usually it is outputs of some other models.

    name

    The name of the new model.

  • You can compose a new model of a list of models assuming one’s output is another’s input.

    Declaration

    Swift

    public convenience init(_ models: [Model], name: String = "")

    Parameters

    models

    The array of models.

    name

    The name of the new model.