MicroGPT.ts - a conversion of Karpathy's MicroGPT to Typescript
    Preparing search index...

    Function gpt

    • Run a single forward pass of the GPT model for one token position.

      This follows GPT-2 with minor differences: RMSNorm instead of LayerNorm, no biases, and ReLU instead of GeLU.

      Parameters

      • tokenId: number

        Token id to embed.

      • posId: number

        Position index within the sequence.

      • keys: Value[][][]

        Per-layer KV cache for keys (mutated: new key appended).

      • values: Value[][][]

        Per-layer KV cache for values (mutated: new value appended).

      • stateDict: StateDict

        Model weights.

      • config: GPTConfig

        Model hyperparameters.

      Returns Value[]

      Logits vector of length vocabSize.