Class DecoderOnlyModel
java.lang.Object
io.github.kirstenali.deepj.models.DecoderOnlyModel
- All Implemented Interfaces:
CausalLM,Persistable,Trainable
- Direct Known Subclasses:
DeepSeekModel,GPTModel,LlamaModel
Shared skeleton for decoder-only transformer models:
token embedding → block stack → final norm → LM-head.
Subclasses pass their concrete TransformerStack to the protected
constructor and provide CausalLM.gradClipNorm().
Models that add positional embeddings (e.g. GPT) override
embed(int[]), backwardEmbeddings(io.github.kirstenali.deepj.tensor.Tensor), and embeddingParameters().
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Projectionprotected final NormLayerprotected final TransformerStackprotected final Embedding -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDecoderOnlyModel(Embedding tokEmb, TransformerStack stack, NormLayer normF, Projection lmHead) -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidapplyInitScale(float factor) voidBack-propagates gradient of the logits through the model.protected voidBack-propagates gradient into embedding layer(s).protected Tensorembed(int[] inputIds) Maps input ids to the initial hidden state.Returns all embedding parameters.forward(int[] inputIds) Maps token ids to logits[seqLen × vocabSize].Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.kirstenali.deepj.models.CausalLM
gradClipNormMethods inherited from interface io.github.kirstenali.deepj.persistence.Persistable
load, save
-
Field Details
-
tokEmb
-
stack
-
normF
-
lmHead
-
-
Constructor Details
-
DecoderOnlyModel
protected DecoderOnlyModel(Embedding tokEmb, TransformerStack stack, NormLayer normF, Projection lmHead)
-
-
Method Details
-
embed
Maps input ids to the initial hidden state. Override to add positional embeddings. -
backwardEmbeddings
Back-propagates gradient into embedding layer(s). Override to include positional. -
embeddingParameters
Returns all embedding parameters. Override to include positional embedding. -
forward
Description copied from interface:CausalLMMaps token ids to logits[seqLen × vocabSize]. -
backward
Description copied from interface:CausalLMBack-propagates gradient of the logits through the model. -
parameters
- Specified by:
parametersin interfacePersistable- Specified by:
parametersin interfaceTrainable
-
applyInitScale
protected final void applyInitScale(float factor)
-