Class Module
java.lang.Object
ai.beestream.jitnn.nn.Module
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
AdaptiveAvgPool, AdaptiveMaxPool, Add, AvgPool1d, AvgPool2d, AvgPool3d, BatchNorm2d, Bert, CELU, CharRnn, Conv1d, Conv2d, Conv3d, ConvTranspose2d, Cube, Dcgan.Discriminator, Dcgan.Generator, Doc2Vec, Dropout, ELU, Embedding, EmbeddingBag, Flatten, GlobalAvgPool2d, GloVe, GPT2, GraphConv, GroupNorm, GRU, HardSigmoid, HardSwish, HardTanh, InstanceNorm, LayerNorm, LeakyReLU, Linear, Llama, LocalResponseNorm, LSTM, MaxPool1d, MaxPool2d, MaxPool3d, Mish, MultiheadAttention, Pad, PReLU, ReLU, ReLU6, RMSNorm, RReLU, SELU, Sequential, Sigmoid, Softplus, Softsign, SyncBatchNorm2d, Tanh, ThresholdedReLU, UNet, Upsample, Vae, Word2Vec
A differentiable building block with parameters and child modules.
A module owns its parameters and buffers, and its children's. close() releases them
on the device. Training a module (forward and backward, zeroGrad, its optimiser) is for
one thread at a time; inference in evaluation mode (Grad.inference) may run from several
threads at once, sharing the weights.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected TensorRegisters persistent state that is not trained (running statistics).buffers()This module's buffers and its children's.protected <M extends Module>
Mchild(M module) Adds a child module; returns it.voidclose()Releases the parameters and buffers of this module and its children, their gradients, and the weights jitNN derived from them (BatchNorm-folded and channels-last copies).abstract TensorApplies the module tox.booleanisClosed()Whetherclose()was called.booleanWhether the module is in training mode (the default).voidOverwrites the parameters and buffers with those ofd, in place, so compiled plans keep using them.protected TensorRegisters a trainable parameter initialised frominit.longThe number of trainable values: the elements of every parameter.This module's parameters and its children's, in registration order.The parameters (parameters.<i>) and buffers (buffers.<i>) in registration order, referring to the live tensors: save it withStateDict.save(Path).train(boolean on) Switches this module and its children to training mode (on) or evaluation mode; returns this module.voidzeroGrad()Clears the gradients of every parameter.
-
Constructor Details
-
Module
public Module()
-
-
Method Details
-
forward
-
parameter
-
buffer
-
buffers
-
child
Adds a child module; returns it. -
parameters
-
zeroGrad
public void zeroGrad()Clears the gradients of every parameter. -
train
Switches this module and its children to training mode (on) or evaluation mode; returns this module. -
isTraining
public boolean isTraining()Whether the module is in training mode (the default). -
parameterCount
public long parameterCount()The number of trainable values: the elements of every parameter. -
stateDict
The parameters (parameters.<i>) and buffers (buffers.<i>) in registration order, referring to the live tensors: save it withStateDict.save(Path). Names are positions, so a checkpoint loads into a model built the same way. -
loadStateDict
Overwrites the parameters and buffers with those ofd, in place, so compiled plans keep using them. Every name, dtype and shape must match. -
close
public void close()Releases the parameters and buffers of this module and its children, their gradients, and the weights jitNN derived from them (BatchNorm-folded and channels-last copies). Using the module afterwards is an error. Plans compiled for it stay cached for a model of the same structure, which reuses them without compiling, and are closed once idle (jitnn.plan.idleExecutions) or byJitnnRuntime.reset(). Closing twice does nothing.- Specified by:
closein interfaceAutoCloseable
-
isClosed
public boolean isClosed()Whetherclose()was called.
-