100% Full API Reference
Complete specification of Tensor, Module, Optimizer, Checkpoint, and Tokenizer classes.
1. Core Tensor Module (termux_train.Tensor)
| Method / Property | Signature | Description |
Tensor(data, requires_grad) | (data: Any, requires_grad: bool = False, dtype: str = 'float32') | Constructs a dynamic autograd graph node. |
backward() | (gradient: Optional[Tensor] = None) | Executes reverse-mode DAG automatic differentiation. |
zero_grad() | (set_to_none: bool = True) | Resets gradients (set_to_none=True optimizes mobile RAM). |
@ (matmul) | (other: Tensor) -> Tensor | 1D~3D matrix multiplication (all 9 rank combinations). |
2. Neural Network Layers (termux_train.nn)
| Class | Key Constructor Parameters | Description |
nn.Linear | in_features: int, out_features: int, bias: bool = True | Fully-connected linear transformation layer. |
nn.LoRALinear | in_features: int, out_features: int, rank: int = 4, alpha: float = 8.0 | Low-Rank Adaptation parameter-efficient adapter layer. |
nn.Embedding | num_embeddings: int, embedding_dim: int | Lookup table for discrete token embeddings. |
nn.LayerNorm | normalized_shape: int, eps: float = 1e-5 | Channel layer normalization. |
nn.RotaryEmbedding | dim: int, max_position_embeddings: int = 2048 | Rotary Position Embedding (RoPE) with O(0) learnable weights. |
nn.TinyTransformerLM | vocab_size, d_model, num_heads, d_ff, num_layers, pos_type | Complete Decoder Transformer with RoPE & KV Cache. |
3. Optimizers & Serialization
| Function / Class | Module | Description |
optim.AdamW | termux_train.optim | Decoupled weight decay Adam optimizer. |
checkpoint.save_safetensors | termux_train.checkpoint | HuggingFace-compatible zero-copy binary serialization. |
checkpoint.save_lora_adapter | termux_train.checkpoint | Saves low-rank matrices only (<100KB adapter footprint). |