Class Sequential

A sequential container.

Modules will be added to it in the order they are passed in the constructor.

The forward() method of Sequential accepts any input and forwards it to the first module. It then forwards the output of that module to the second module, and so on, finally returning the output of the last module.

Hierarchy

Indexable

[index: number]: Module

Constructors

Accessors

  • get [toStringTag](): string
  • Returns string

  • get children(): Module[]
  • Returns the immediate children (submodules) of this module.

    Returns Module[]

  • get namedChildren(): [string | number, Module][]
  • Returns the immediate children (submodules) of this module along with their names.

    Returns [string | number, Module][]

  • get training(): boolean
  • Returns boolean

Methods

  • Adds a child module of the current module.

    The module can be accessed as a property using the given name.

    Parameters

    • name: string | number

      name of the child module

    • module: Module

      child module to be added

    Returns void

  • Loads the state of the module and its descendants from the given state dictionary.

    Parameters

    • stateDict: StateDict

      The state dictionary containing the state of the module to load.

    Returns void

  • Parameters

    • prefix: string = ""
    • recurse: boolean = true
    • removeDuplicate: boolean = true

    Returns Generator<[string, null | Tensor], any, unknown>

  • Returns this module and its descendants' along with their prefixed names.

    Parameters

    • Optional memo: Set<Module>

      is a set of modules used to avoid double counting.

    • prefix: string = ""

      is prependended to the names of the modules.

    • removeDuplicate: boolean = true

      is a boolean indicating whether to remove duplicate modules.

    Returns Generator<[string | number, Module], any, unknown>

    a generator of [prefixed name, module] pairs.

  • Gets this module and its descendants' (if recurse = true) parameters along with their prefixed names.

    Parameters

    • prefix: string = ""

      is prependended to the names of the parameters

    • recurse: boolean = true

      whether to include submodule parameters

    • removeDuplicate: boolean = true

      whether to remove duplicate parameters

    Returns Generator<[string, Parameter], any, unknown>

    a generator of [prefixed name, parameter] pairs

  • Change if autograd should record operations on parameters in this module.

    Parameters

    • requiresGrad: boolean = true

      whether to enable gradient calculation for parameters in this module.

    Returns ThisType<Module>

    this module

  • Returns the state dictionary of the module and its descendants.

    Parameters

    • Optional destination: StateDict

      An optional state dictionary to update with the module's state.

    • prefix: string = ""

      A string to prepend to the names of the state entries (default is an empty string).

    • keepVars: boolean = true

      A boolean flag, if true keeps the tensors attached to autograd (default is true).

    Returns StateDict

    The updated state dictionary containing the module's state.

  • Produces a multiline readable string of the module and its descendants.

    Returns string

    A string representation of the module and its descendants.

  • Sets the module in training mode.

    Parameters

    • mode: boolean = true

      whether to set training mode (true) or evaluation mode (false).

    Returns ThisType<Module>

    this module

  • Zeros out the gradients of all parameters. That can be accomplished either by setting the grad property to null (setToNull=true) or by filling the gradient tensor with zeros (setToNull=false).

    Parameters

    • setToNull: boolean = true

      whether to set gradients to null (true) or to zero tensors (false).

    Returns ThisType<Module>

    this module

Generated using TypeDoc