MCPcopy Create free account

hub / github.com/FareedKhan-dev/train-llm-from-scratch / functions

Functions604 in github.com/FareedKhan-dev/train-llm-from-scratch

↓ 3 callersFunctionevaluate_task
Score ``examples`` and return the task's metrics, each with its standard error. ``choice`` tasks report ``acc`` and ``acc_norm``; ``lambada`` rep
src/benchmarks/tasks.py:91
↓ 3 callersMethodfrom_mapping
Build from any mapping (a JSON config, a checkpoint ``cfg``), ignoring unrelated keys.
src/models/modern/config.py:109
↓ 3 callersFunctionget_tokenizer
Return the shared r50k_base encoder (cached so we build it once).
src/post_training/chat_template.py:53
↓ 3 callersFunctionimplicit_accuracy
Fraction of pairs where the implicit (DPO/IPO/SimPO/KTO/ORPO) reward prefers chosen.
src/post_training/dpo.py:166
↓ 3 callersMethoditer_content
(self, size: int)
tests/test_data_tools.py:62
↓ 3 callersFunctionlist_checkpoints
Return periodic checkpoints sorted by training step.
scripts/train_transformer.py:183
↓ 3 callersFunctionmodel_config_from_checkpoint
Return the model settings stored in a checkpoint. Post-training stages save them under ``cfg`` and the legacy trainer under ``config``. Very
src/checkpoint.py:89
↓ 3 callersFunctionnewton_schulz
Approximately orthogonalize ``G`` (all singular values pushed to about 1).
src/optim/muon.py:41
↓ 3 callersFunctionppo_minibatch_loss
The loss of one PPO minibatch: the clipped policy loss, ``vf_coef`` times the value loss, and, when ``ent_coef`` is set, minus ``ent_coef`` times
scripts/train_ppo.py:63
↓ 3 callersFunctionppo_policy_loss
Clipped surrogate policy loss. Returns (loss, clip_fraction).
src/post_training/ppo.py:68
↓ 3 callersFunctionppo_value_loss
Clipped value-function loss (0.5 * max of clipped/unclipped squared error).
src/post_training/ppo.py:84
↓ 3 callersFunctionquantize_int8
Replace every ``nn.Linear`` (except names in ``skip``) by :class:`Int8Linear`, in place.
src/inference/quantize.py:56
↓ 3 callersMethodraise_for_status
(self)
tests/test_data_tools.py:58
↓ 3 callersFunctionrestore_training_checkpoint
Restore model/optimizer state and return ``(next_step, losses)``. Older checkpoints did not have ``last_completed_step``. For those, ``steps
scripts/train_transformer.py:287
↓ 3 callersFunctionsample_next_token
Pick the next token id for every row of ``logits``.
src/inference/sampling.py:59
↓ 3 callersFunctionsave_training_checkpoint
Save model, optimizer, loss history, and LR schedule metadata. ``step`` is the last completed zero-based training step, so resume starts at
scripts/train_transformer.py:230
↓ 3 callersFunctionunwrap_model
Return the plain module behind any mix of DDP / DataParallel / torch.compile wrappers.
src/checkpoint.py:30
↓ 3 callersFunctionwhiten
Normalize advantages to zero mean / unit std over masked (response) positions.
src/post_training/ppo.py:60
↓ 2 callersFunction_actor
()
tests/test_ppo_entropy.py:16
↓ 2 callersFunction_answers_match
(pred: float | None, gold: float | None)
src/post_training/rewards/verifiers.py:24
↓ 2 callersFunction_batch
()
tests/test_ppo_entropy.py:21
↓ 2 callersFunction_build_parser
(cfg_cls: type, extra: dict | None)
src/post_training/cli.py:24
↓ 2 callersFunction_cfg
(ent_coef: float)
tests/test_ppo_entropy.py:32
↓ 2 callersFunction_compute_losses
(policy, ref, batch, cfg, ctx)
scripts/train_dpo.py:51
↓ 2 callersFunction_header_for
(role: str)
src/post_training/chat_template.py:63
↓ 2 callersFunction_log
(job_id: str)
ui/jobs.py:33
↓ 2 callersFunction_mean_over_answers
Average over the answers that have at least one trained token. ``--filter_groups`` masks out every token of a skipped group. Counting those empty
src/post_training/grpo.py:71
↓ 2 callersFunction_pair_rewards
Forward chosen+rejected in one pass; return (chosen_rewards, rejected_rewards).
scripts/train_reward.py:36
↓ 2 callersFunction_pairs
()
tests/test_post_training_losses.py:15
↓ 2 callersFunction_preference_nll
``-log sigmoid(logits)``, optionally hedged against flipped labels (conservative DPO).
src/post_training/dpo.py:35
↓ 2 callersFunction_record_training_batches
Record the first column of every batch the training loader yields (the one main() reads).
tests/test_resume_data_order.py:81
↓ 2 callersFunction_reg
(job_id: str)
ui/jobs.py:29
↓ 2 callersFunction_shard
(path: Path, n_docs: int)
tests/test_data_tools.py:25
↓ 2 callersFunction_tiny_config
()
tests/test_checkpoint_resume.py:32
↓ 2 callersFunction_tiny_model
()
tests/test_checkpoint_resume.py:27
↓ 2 callersFunction_train
(monkeypatch: pytest.MonkeyPatch, tiny_data: dict[str, str], *extra: str)
tests/test_student_track.py:41
↓ 2 callersFunction_write_registry
(job_id: str, data: dict)
ui/jobs.py:37
↓ 2 callersFunctionaccumulate_gradients
Backpropagate one optimizer step over its micro-batches and return its SFT loss. The summed loss is divided by the number of trained tokens in th
scripts/train_sft.py:65
↓ 2 callersFunctionactor_logp_values
One forward through the actor-critic -> (logp, values) in the action frame (B,T-1). With ``with_entropy`` it also returns the per-token entropy o
scripts/train_ppo.py:48
↓ 2 callersFunctionadamw_param_groups
Decay the >=2D weight matrices, not biases / norms / 1D params (the standard GPT recipe).
src/optim/__init__.py:12
↓ 2 callersFunctionarithmetic_prompts
(n: int, max_val: int, seed: int)
scripts/prepare_rl_prompts.py:49
↓ 2 callersFunctionbatched_generate
Generate a response string for each tokenized prompt, returned in input order. Prompts are grouped by identical length (the model has no pad
src/post_training/evaluation.py:24
↓ 2 callersFunctionbigram_logits
A fixed bigram model: p(next = j | current = i) is proportional to exp(table[i, j]).
tests/test_benchmarks.py:34
↓ 2 callersFunctionbigram_logp
(prev: int, nxt: int)
tests/test_benchmarks.py:40
↓ 2 callersFunctionbuild_optimizer
``"adamw"`` or ``"muon"`` (Muon on hidden matrices, AdamW on everything else).
src/optim/__init__.py:23
↓ 2 callersFunctioncount_targets
The number of target positions :func:`sft_loss` trains on in a ``(B, T)`` mask.
src/post_training/sft.py:53
↓ 2 callersFunctiondense_reward
Fraction of generated tokens equal to the target token (dense, easy to learn).
tests/verify_rl_optimizes.py:25
↓ 2 callersFunctiondpo_loss
Standard DPO loss. Inputs are summed response log-probs (B,). ``L = -log sigmoid(beta * [(pi_c - pi_r) - (ref_c - ref_r)])``. With ``lab
src/post_training/dpo.py:42
↓ 2 callersMethodforward_embedding
Applies the hidden linear layer followed by ReLU activation. Args: x (torch.Tensor): Input tensor. Returns:
src/models/mlp.py:43
↓ 2 callersMethodforward_hidden
Hidden states after the final norm (what ``lm_head`` reads; reward/value heads reuse it).
src/models/modern/model.py:80
↓ 2 callersMethodfrom_dict
(cls, data: Mapping[str, Any])
src/tokenizer/bpe.py:241
↓ 2 callersFunctionfull
()
scripts/prepare_pretrain_data.py:98
↓ 2 callersFunctiongather_last
Given per-token ``values`` (B, T) and ``seq_lengths`` (B,), return the value at the last real token of each row, i.e. ``values[i, seq_lengths
src/post_training/utils.py:143
↓ 2 callersFunctiongenerate_reply
Generate a response to ``user_text``. - chat mode (default): wraps the prompt in the chat template (optionally with a ``system`` messa
src/post_training/inference.py:44
↓ 2 callersFunctionget_prompt_iterator
Infinitely yield lists of ``prompts_per_iter`` rows (this rank's shard).
data_loader/prompt_dataset.py:20
↓ 2 callersFunctionget_sft_batch_iterator
Yield ``(tokens, loss_mask, epoch)`` batches from a packed SFT HDF5 file. Rows are sharded across ranks (each rank sees a disjoint stride) s
data_loader/sft_dataset.py:18
↓ 2 callersFunctionhas_well_formed_answer
True iff there is exactly one well-formed ``<answer>...</answer>`` block.
src/post_training/rewards/parsing.py:85
↓ 2 callersFunctionipo_loss
IPO: ``L = (h - 1 / (2 beta))^2`` with ``h`` the DPO log-ratio gap on per-token averages. DPO keeps pushing ``h`` up even after a pair is cl
src/post_training/dpo.py:69
↓ 2 callersFunctionk3_kl
Per-token unbiased, non-negative KL estimator (Schulman's k3) for KL(policy||ref).
src/post_training/grpo.py:65
↓ 2 callersFunctionload_reward_model
Reconstruct a trained :class:`RewardModel` (backbone + reward head) from a reward checkpoint saved by ``scripts/train_reward.py``.
src/post_training/reward_model.py:20
↓ 2 callersFunctionload_trained_model
Rebuild the model, its tokenizer and its training window from a checkpoint.
scripts/generate_text.py:43
↓ 2 callersFunctionlora_parameter_count
``(trainable, total)`` parameter counts, to report how small the update is.
src/models/lora.py:110
↓ 2 callersFunctionlr_at
Dispatch to the schedule called ``schedule``.
src/optim/schedules.py:70
↓ 2 callersFunctionmasked_mean_per_row
Per-row (B,) mean of ``values`` (B,T) over masked positions.
src/post_training/utils.py:135
↓ 2 callersFunctionmerge_lora
Fold every LoRA update into its base layer (in place) and make all weights trainable again.
src/models/lora.py:99
↓ 2 callersFunctionmodel_size_bytes
Bytes of all parameters and buffers (shared tensors counted once).
src/inference/quantize.py:66
↓ 2 callersFunctionmoe_balance_loss
The Mixture-of-Experts balancing loss of the last forward pass, times its coefficient. The modern model adds this loss itself only when it is giv
src/post_training/utils.py:96
↓ 2 callersFunctionmuon_param_groups
Split ``model`` into a Muon group (2D hidden weight matrices) and an AdamW group (embeddings, the output layer, norms, biases). Matches the u
src/optim/muon.py:143
↓ 2 callersFunctionpack_examples
Pack a list of ``(ids, loss_mask)`` examples into fixed-length ``context_length`` rows by concatenating them and slicing. Examples are alread
src/post_training/sft.py:58
↓ 2 callersFunctionparse_number
Parse the first number out of a string, tolerating ``$`` and thousands commas.
src/post_training/rewards/parsing.py:32
↓ 2 callersFunctionpreference_accuracy
Fraction of pairs where the model scores the chosen response higher.
src/post_training/reward_train.py:23
↓ 2 callersFunctionprune_old_checkpoints
Keep only the most recent N periodic checkpoints when requested.
scripts/train_transformer.py:334
↓ 2 callersFunctionresolve_resume_path
Resolve a resume argument. ``--resume`` with no value uses the latest periodic checkpoint in checkpoint_dir. ``--resume path/to/file.pt`
scripts/train_transformer.py:195
↓ 2 callersFunctionrollout_prompts
Generate one completion per (possibly variable-length) tokenized prompt and merge the results into padded tensors. Length-buckets prompts (th
src/post_training/rollout.py:175
↓ 2 callersFunctionrope_frequencies
The rotation speed ``theta_i`` of each of the ``dim / 2`` pairs.
src/models/modern/rope.py:25
↓ 2 callersFunctionrun
(*extra: str)
tests/test_resume_data_order.py:113
↓ 2 callersFunctionset_optimizer_lr
Set all optimizer parameter groups to the same learning rate.
scripts/train_transformer.py:224
↓ 2 callersFunctionsimpo_loss
SimPO: ``L = -log sigmoid(beta * avg_logp(chosen) - beta * avg_logp(rejected) - gamma)``. Two differences from DPO: no reference model (chea
src/post_training/dpo.py:93
↓ 2 callersFunctionstrip_wrapper_prefixes
Remove leading wrapper prefixes from every key, in any order and any nesting depth. ``module._orig_mod.lm_head.weight`` and ``_orig_mod.modu
src/checkpoint.py:43
↓ 2 callersFunctiontiny_model
()
tests/verify_rl_optimizes.py:31
↓ 2 callersMethodto_dict
(self)
src/tokenizer/bpe.py:231
↓ 2 callersFunctiontype_name
Short human name of a field type, for help texts and error messages.
config/loader.py:66
↓ 1 callersMethod__init__
Initializes the attention head. Args: head_size (int): The dimensionality of the key, query, and value projections.
src/models/attention.py:21
↓ 1 callersMethod__init__
(self, cfg: ModernConfig, layer_idx: int)
src/models/modern/attention.py:63
↓ 1 callersMethod_adamw_step
(self, group: dict[str, Any])
src/optim/muon.py:122
↓ 1 callersFunction_alive_windows
Ask Windows whether ``pid`` is still running (never os.kill: on Windows it terminates).
ui/jobs.py:53
↓ 1 callersFunction_cap_of
(model)
src/post_training/rollout.py:169
↓ 1 callersFunction_cfg_to_dict
(cfg: Any)
src/post_training/utils.py:155
↓ 1 callersFunction_classic
()
tests/test_lora.py:13
↓ 1 callersFunction_clean_markdown
(text: str)
ui/docs_render.py:19
↓ 1 callersFunction_coerce_blank
Map an empty text box back to None for optional (``| None``) string fields.
ui/config_forms.py:38
↓ 1 callersFunction_cpu
(n_embed: int, n_head: int, n_blocks: int, context: int, steps: int, batch: int, lr: float, name: str)
config/presets.py:37
↓ 1 callersMethod_encode_chunk
(self, chunk: str)
src/tokenizer/bpe.py:178
↓ 1 callersFunction_encode_ordinary
Encode text as ordinary tokens (no special-token handling).
src/post_training/chat_template.py:58
↓ 1 callersFunction_encode_response
Encode assistant content plus its EOT, without duplicating the role header.
data_loader/preference_dataset.py:35
↓ 1 callersFunction_ensure_job_dir
()
ui/jobs.py:25
↓ 1 callersFunction_first_difference
Index of the first token where ``a`` and ``b`` differ (None if they are identical).
data_loader/preference_dataset.py:42
↓ 1 callersFunction_grads
(model: torch.nn.Module)
tests/test_sft_accumulation.py:26
↓ 1 callersFunction_greedy
(model: nn.Module, idx: torch.Tensor, n: int)
tests/test_inference.py:23
↓ 1 callersFunction_load
(path, dev)
ui/pages/9_Chat.py:37
← previousnext →101–200 of 604, ranked by callers