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 : ModelIOConvertible
  • Whether the existing model is for testing or training.

    Declaration

    Swift

    public var testing: Bool
  • Declaration

    Swift

    public let cModel: OpaquePointer
  • Declaration

    Swift

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

    Swift

    @inlinable
    public func callAsFunction(_ inputs: [ModelIOConvertible]) -> 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 }
  • Shortcut for weight parameter.

    Declaration

    Swift

    public var weight: Parameters { get }
  • Shortcut for bias parameter.

    Declaration

    Swift

    public var bias: Parameters { get }
  • Whether this is initialized as trainable model or not.

    Declaration

    Swift

    public var trainable: Bool? { get }
  • Whether to enable gradient checkpointing for this model. Once it is enabled, we will re-run the model forward pass again during backward pass. This is effective at reducing memory usage.

    Declaration

    Swift

    public var gradientCheckpointing: Bool { get set }
  • Whether to enable memory reduction for this model. The current supported memory reduction technique is to redo datatype conversion during backward pass if needed.

    Declaration

    Swift

    public var memoryReduction: Bool { get set }
  • Specify the maximum number of streams we need to allocate to run this model.

    Declaration

    Swift

    public var maxConcurrency: StreamContext.Concurrency { get set }
  • 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.

    • isEager: Whether we want to push compilation as far as possible up until the actual execution.

    Declaration

    Swift

    public func compile(inputs: [DynamicGraph_Any], isEager: Bool = false)
  • 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..., isEager: Bool = false)
  • You can compose a new model from old models when applying IO on them.

    Declaration

    Swift

    public convenience init(
      _ inputs: [IO], _ outputs: [IO], trainable: Bool? = nil, 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], trainable: Bool? = nil, name: String = "")

    Parameters

    models

    The array of models.

    name

    The name of the new model.