MCPcopy Create free account

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

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

↓ 2 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:230
↓ 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:180
↓ 2 callersFunctionset_optimizer_lr
Set all optimizer parameter groups to the same learning rate.
scripts/train_transformer.py:167
↓ 2 callersFunctionsft_loss
Masked next-token cross-entropy. Args: logits: (B, T, V) model logits for ``tokens``. tokens: (B, T) packed token ids.
src/post_training/sft.py:18
↓ 2 callersFunctiontiny_model
()
tests/verify_rl_optimizes.py:31
↓ 2 callersFunctionwrite_jsonl
(rows: list[dict], path: str)
scripts/prepare_preference_data.py:88
↓ 2 callersFunctionwrite_packed
(examples, context_length: int, out_path: str)
scripts/prepare_sft_data.py:97
↓ 1 callersMethod__init__
Initializes the attention head. Args: head_size (int): The dimensionality of the key, query, and value projections.
src/models/attention.py:19
↓ 1 callersFunction_cap_of
(model)
src/post_training/rollout.py:174
↓ 1 callersFunction_cfg_to_dict
(cfg: Any)
src/post_training/utils.py:144
↓ 1 callersFunction_clean_markdown
(text: str)
ui/docs_render.py:19
↓ 1 callersFunction_collate
(rows: list[dict], max_len: int, device: str)
data_loader/preference_dataset.py:33
↓ 1 callersFunction_deep_merge
Recursively merge ``src`` into ``dst`` (nested-dict aware; future-proof).
config/loader.py:28
↓ 1 callersFunction_ensure_job_dir
()
ui/jobs.py:25
↓ 1 callersFunction_load
(path, dev)
ui/pages/9_Chat.py:34
↓ 1 callersFunction_model_context_length
(model)
src/post_training/evaluation.py:18
↓ 1 callersFunction_nullcm
()
scripts/pretrain_base.py:153
↓ 1 callersFunction_resolve_base
(json_path: str | None, base_path: str | None)
config/loader.py:38
↓ 1 callersFunction_strip_ddp_prefix
Remove a leading ``module.`` from keys saved by DistributedDataParallel.
src/post_training/utils.py:67
↓ 1 callersFunctionalpaca_to_messages
(ex: dict)
scripts/prepare_sft_data.py:46
↓ 1 callersFunctionapprox_kl
Mean approximate KL(old || new) over response tokens (a PPO health metric).
src/post_training/ppo.py:98
↓ 1 callersFunctionarithmetic_prompts
(n: int, max_val: int, seed: int)
scripts/prepare_rl_prompts.py:46
↓ 1 callersFunctionautocast_ctx
()
scripts/train_transformer.py:455
↓ 1 callersFunctionbradley_terry_loss
Mean ``-log sigmoid(chosen - rejected)`` over a batch of preference pairs.
src/post_training/reward_train.py:18
↓ 1 callersFunctionbuild_argv
Construct the exact command (torchrun for multi-GPU, else python).
ui/jobs.py:74
↓ 1 callersFunctioncollect_examples
(context_length: int, limit_per_set: int | None)
scripts/prepare_sft_data.py:60
↓ 1 callersFunctioncurrent_lr
Read the learning rate from the first optimizer parameter group.
scripts/train_transformer.py:155
↓ 1 callersFunctiondefault_checkpoint_dir
Return a checkpoint directory tied to the configured final model path.
scripts/train_transformer.py:107
↓ 1 callersFunctiondolly_to_messages
(ex: dict)
scripts/prepare_sft_data.py:53
↓ 1 callersFunctiondownload
(url: str, dest: str)
scripts/prepare_pretrain_data.py:44
↓ 1 callersFunctiondownload_dataset
Manages downloading of the dataset, including both validation and training files. Args: val_url (str): URL for the validation da
scripts/data_download.py:29
↓ 1 callersFunctiondpo_loss
Standard DPO loss. Inputs are summed response log-probs (B,). Returns ``(loss, chosen_reward, rejected_reward)`` where the implicit rewards
src/post_training/dpo.py:21
↓ 1 callersFunctionestimate_loss
(model, cfg, ctx, iters: int)
scripts/pretrain_base.py:38
↓ 1 callersFunctionestimate_memory_budget
Print a rough training VRAM budget so users can predict OOM before launching. AdamW keeps fp32 weights + grads + two moment buffers (~16 byt
scripts/train_transformer.py:72
↓ 1 callersFunctionfilter_logits
Apply temperature, then optional top-k and nucleus (top-p) filtering to a batch of next-token logits ``(B, vocab)``. Returns logits with filt
src/post_training/rollout.py:59
↓ 1 callersMethodforward_embedding
Applies the hidden linear layer followed by ReLU activation. Args: x (torch.Tensor): Input tensor. Returns:
src/models/mlp.py:43
↓ 1 callersFunctionfrom_hh
(max_n: int, split: str)
scripts/prepare_preference_data.py:37
↓ 1 callersFunctionfrom_ultrafeedback
(max_n: int, split: str)
scripts/prepare_preference_data.py:56
↓ 1 callersFunctiongenerate_text
Generates text using a pre-trained Transformer model. Args: model_path (str): Path to the saved model checkpoint. input_text
scripts/generate_text.py:14
↓ 1 callersFunctionget_device_report
Build a short report describing the runtime environment: PyTorch/CUDA versions and, when running on a GPU, its name, capability, and total VR
scripts/train_transformer.py:32
↓ 1 callersFunctiongsm8k_to_messages
Reformat a GSM8K (question, answer) into chat messages whose assistant turn uses the <think>...</think><answer>N</answer> structure.
scripts/prepare_sft_data.py:34
↓ 1 callersFunctioniter_texts
(zst_path: str)
scripts/prepare_pretrain_data.py:60
↓ 1 callersFunctionkto_loss
KTO from paired data: chosen = desirable, rejected = undesirable, with a reference-KL baseline estimated (detached) from the batch's mean log
src/post_training/dpo.py:71
↓ 1 callersFunctionload_checkpoint
(model_path: str, device: str)
scripts/generate_text.py:8
↓ 1 callersFunctionload_checkpoint_file
Load a checkpoint while supporting both newer and older PyTorch versions.
scripts/train_transformer.py:99
↓ 1 callersFunctionload_prompt_rows
(path: str)
data_loader/prompt_dataset.py:15
↓ 1 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:21
↓ 1 callersFunctionlr_for_step
Return the learning rate that should be active at a given step.
scripts/train_transformer.py:160
↓ 1 callersFunctionmain
()
scripts/train_ppo.py:55
↓ 1 callersFunctionmain
()
scripts/generate_text.py:56
↓ 1 callersFunctionmain
()
scripts/train_reward.py:59
↓ 1 callersFunctionmain
()
scripts/prepare_pretrain_data.py:121
↓ 1 callersFunctionmain
()
scripts/chat.py:24
↓ 1 callersFunctionmain
Main function to parse arguments and orchestrate the dataset download process.
scripts/data_download.py:58
↓ 1 callersFunctionmain
()
scripts/pretrain_base.py:56
↓ 1 callersFunctionmain
()
scripts/train_sft.py:50
↓ 1 callersFunctionmain
Main function to parse arguments, validate directories, and process files.
scripts/data_preprocess.py:81
↓ 1 callersFunctionmain
()
scripts/train_grpo.py:43
↓ 1 callersFunctionmain
()
scripts/train_dpo.py:74
↓ 1 callersFunctionmain
()
scripts/train_transformer.py:416
↓ 1 callersFunctionmain
()
scripts/prepare_sft_data.py:107
↓ 1 callersFunctionmain
()
scripts/prepare_preference_data.py:96
↓ 1 callersFunctionmain
()
scripts/prepare_rl_prompts.py:57
↓ 1 callersFunctionmain
()
scripts/eval_post_training.py:53
↓ 1 callersFunctionmain
()
images/make_diagrams.py:152
↓ 1 callersFunctionmodel_from_ckpt
(ckpt_path: str, device: str, overrides: dict | None = None)
scripts/eval_post_training.py:28
↓ 1 callersFunctionorpo_loss
ORPO (reference-free). Uses per-token MEAN log-probs. ``L = NLL(chosen) + lambda * -log sigmoid(log_odds_chosen - log_odds_rejected)`` w
src/post_training/dpo.py:48
↓ 1 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:41
↓ 1 callersFunctionparse_args
()
scripts/train_transformer.py:348
↓ 1 callersFunctionplot_gsm8k
()
images/plot_artifacts.py:44
↓ 1 callersFunctionplot_loss
()
images/plot_artifacts.py:21
↓ 1 callersFunctionprint_table
(path: str)
scripts/eval_post_training.py:45
↓ 1 callersMethodproject_embedding
Applies the projection linear layer. Args: x (torch.Tensor): Input tensor. Returns: torch.Tensor: O
src/models/mlp.py:56
↓ 1 callersFunctionrender_doc
Render the diagram (if any) + the prose of a docs markdown file.
ui/docs_render.py:29
↓ 1 callersFunctionrender_form
(stage: Stage, smoke: bool = False, nproc: int = 1)
ui/config_forms.py:52
↓ 1 callersFunctionreward_margin
Mean reward gap (chosen - rejected); a useful training diagnostic.
src/post_training/reward_train.py:28
↓ 1 callersFunctionseq_lengths_from_mask
Real token count per row = last response position + 1 (or prompt_len if no response).
scripts/train_ppo.py:47
↓ 1 callersFunctionseq_lengths_from_mask
(response_mask, prompt_lens)
scripts/train_grpo.py:36
↓ 1 callersFunctionsequence_logprobs
Sequence-level summed log-prob over response tokens (used by DPO/KTO/ORPO). Returns ``(sum_logprob, n_tokens)`` each shape (B,). The per-tok
src/post_training/rollout.py:268
↓ 1 callersFunctionshard_urls
(split: str, num_shards: int)
scripts/prepare_pretrain_data.py:38
↓ 1 callersFunctionsmoke
Return an instance of ``cfg_cls`` shrunk to the tiny SMOKE model dims.
config/post_training_config.py:176
↓ 1 callersFunctiontail_log
(job_id: str, max_bytes: int = 16000)
ui/jobs.py:127
↓ 1 callersFunctiontest_build_from_config
()
tests/test_post_training_smoke.py:128
↓ 1 callersFunctiontest_chat_template_masking
()
tests/test_post_training_smoke.py:104
↓ 1 callersFunctiontest_checkpoint_round_trip_and_latest_resume
()
tests/test_checkpoint_resume.py:41
↓ 1 callersFunctiontest_checkpoint_save_failure_does_not_leave_partial_file
()
tests/test_checkpoint_resume.py:81
↓ 1 callersFunctiontest_compute_logprobs_matches_manual
()
tests/test_post_training_smoke.py:38
↓ 1 callersFunctiontest_context_cap_enforced
()
tests/test_post_training_smoke.py:66
↓ 1 callersFunctiontest_forward_hidden_matches_forward
()
tests/test_post_training_smoke.py:28
↓ 1 callersFunctiontest_frozen_copy_and_reductions
()
tests/test_post_training_smoke.py:92
↓ 1 callersFunctiontest_gae_masks_outside_response
()
tests/test_rl_math.py:27
↓ 1 callersFunctiontest_gae_reward_to_go
()
tests/test_rl_math.py:13
↓ 1 callersFunctiontest_group_advantages
()
tests/test_rl_math.py:59
↓ 1 callersFunctiontest_grpo_loss_and_kl
()
tests/test_rl_math.py:68
↓ 1 callersFunctiontest_ppo_losses
()
tests/test_rl_math.py:45
↓ 1 callersFunctiontest_reward_parsing
()
tests/test_post_training_smoke.py:117
↓ 1 callersFunctiontest_rollout_logprobs_consistent
()
tests/test_post_training_smoke.py:51
↓ 1 callersFunctiontest_value_and_reward_heads
()
tests/test_post_training_smoke.py:74
↓ 1 callersFunctiontest_whiten
()
tests/test_rl_math.py:36
↓ 1 callersMethodtoken_rewards
Per-token scalar reward (B, T) -- useful for diagnostics / dense shaping.
src/post_training/reward_model.py:51
← previousnext →101–200 of 252, ranked by callers