Transformer

class Transformer(val vocabularySize: Int, val dimension: Int, val numLayers: Int, val numHeads: Int, val hiddenDimension: Int = 4 * dimension, val numKeyValueHeads: Int = numHeads, val normEps: Float = 1.0E-6f, val ropeTheta: Float = 10000.0f, val ropeScaling: RoPEScaling? = null, quantization: Quantization? = null) : Module(source)

Constructors

Link copied to clipboard
constructor(vocabularySize: Int, dimension: Int, numLayers: Int, numHeads: Int, hiddenDimension: Int = 4 * dimension, numKeyValueHeads: Int = numHeads, normEps: Float = 1.0E-6f, ropeTheta: Float = 10000.0f, ropeScaling: RoPEScaling? = null, quantization: Quantization? = null)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
Link copied to clipboard
fun decode(token: Int, cache: KVCache, buffers: InferenceBuffers): Tensor
Link copied to clipboard
open override fun forward(input: Tensor): Tensor
fun forward(indices: IntArray): Tensor
fun forward(input: Tensor, sequenceLength: Int): Tensor
fun forward(indices: IntArray, cache: KVCache): Tensor
Link copied to clipboard
open fun forwardInto(input: Tensor, out: Tensor): Tensor
Link copied to clipboard
fun generate(prompt: IntArray, maxTokens: Int, stopTokens: Set<Int> = emptySet()): IntArray
fun generate(prompt: IntArray, maxTokens: Int, stopTokens: Set<Int>, prefix: PromptPrefix): IntArray
fun generate(prompt: IntArray, maxTokens: Int, stopTokens: Set<Int>, sampling: Sampling): IntArray
fun generate(prompt: String, tokenizer: Tokenizer, maxTokens: Int, stopTokens: Set<Int> = emptySet()): String
fun generate(prompt: IntArray, maxTokens: Int, stopTokens: Set<Int>, prefix: PromptPrefix, sampling: Sampling): IntArray
Link copied to clipboard
fun generateStream(prompt: IntArray, maxTokens: Int, stopTokens: Set<Int> = emptySet()): Sequence<Int>
fun generateStream(prompt: IntArray, maxTokens: Int, stopTokens: Set<Int>, prefix: PromptPrefix): Sequence<Int>
fun generateStream(prompt: IntArray, maxTokens: Int, stopTokens: Set<Int>, sampling: Sampling): Sequence<Int>
fun generateStream(prompt: String, tokenizer: Tokenizer, maxTokens: Int, onToken: (String) -> Unit)
fun generateStream(prompt: IntArray, maxTokens: Int, stopTokens: Set<Int>, prefix: PromptPrefix, sampling: Sampling): Sequence<Int>
fun generateStream(prompt: String, tokenizer: Tokenizer, maxTokens: Int, stopTokens: Set<Int>, onToken: (String) -> Unit)
Link copied to clipboard
Link copied to clipboard
operator fun invoke(input: Tensor): Tensor
Link copied to clipboard
Link copied to clipboard
fun loss(input: Tensor, targets: Tensor, ignoreIndex: Int = IGNORE_INDEX): Tensor
fun loss(indices: IntArray, targets: IntArray, ignoreIndex: Int = IGNORE_INDEX): Tensor
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun newCache(maxSequenceLength: Int): KVCache
Link copied to clipboard
fun newInferenceBuffers(maxSequenceLength: Int): InferenceBuffers
Link copied to clipboard
Link copied to clipboard
open override fun parameters(): List<Tensor>
Link copied to clipboard
fun prefill(prompt: IntArray, cache: KVCache, buffers: InferenceBuffers): Tensor
Link copied to clipboard
fun quantize(quantization: Quantization): Transformer
Link copied to clipboard
fun saveQuantized(file: File)
Link copied to clipboard
Link copied to clipboard