palm-modeling
Operate the PaLM transformer core in palm-rlhf-pytorch: construction, loss/generation checks, LoRA finetuning scopes, flash-attention choices, and reference-only pretraining.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- palm-modeling
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Operate the PaLM transformer core in palm-rlhf-pytorch: construction, loss/generation checks, LoRA finetuning scopes, flash-attention choices, and reference-only pretraining.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-reference.md11.2 KB
- 参考文档references/pretraining-workflows.md2.0 KB
- 参考文档references/troubleshooting.md2.4 KB
- 脚本scripts/tiny_palm_smoke.py3.5 KB
03 SKILL.md 正文
PaLM Modeling
Use this sub-skill when a task is about the package's base PaLM transformer rather than reward models or policy-optimization trainer loops.
Route Here For
- Constructing a
PaLMmodel for autoregressive language modeling or non-causal embedding use. - Running a tiny loss/backward/logits/embedding/generation smoke check with
scripts/tiny_palm_smoke.py. - Understanding
PaLM.forward,PaLM.generate, sampling helpers, embedding/logit return modes, save/load, dropout changes, and LoRA finetune scopes. - Deciding whether to enable
flash_attn=True; this package uses PyTorch scaled-dot-product attention, not the externalflash-attnpackage. - Adapting the repository's PaLM pretraining flow as a reference-only recipe without running the expensive source training script.
Do Not Use This For
- Reward scoring, binned rewards, prompt masks, or implicit process rewards; route those to the
reward-modelingsub-skill. - PPO, GRPO, TPO, FlowRL,
RLHFTrainer, or post-training loops; route those to thepolicy-optimizationsub-skill. - Full-scale enwik8 training or benchmark-quality model recovery. This sub-skill covers mechanics and bounded checks, not long training.
Start Here
- For API facts and shapes, read
references/api-reference.md. - For the distilled pretraining recipe and why the original training flow is reference-only, read
references/pretraining-workflows.md. - For common failures, read
references/troubleshooting.md. - To verify an installed package quickly, run the bundled helper instead of any source-repo script:
python sub-skills/palm-modeling/scripts/tiny_palm_smoke.py --device auto --check-lora
If running from inside this sub-skill directory, use:
python scripts/tiny_palm_smoke.py --device auto --check-lora
Operating Notes
- Prefer device-neutral examples: create a
torch.device, move model and tensors with.to(device), and avoid README-style unconditional.cuda()calls on CPU hosts. - Keep generation targets explicit:
generate(seq_len, prompt=...)treatsseq_lenas the target total length. With the defaultreturn_seq_without_prompt=True, the returned tensor is only the generated suffix of lengthseq_len - prompt_lenwhenseq_len > prompt_len. - Use
palm.palm_parameters()for base pretraining optimizers andpalm.finetune_parameters(scope)only after creating a matching LoRA scope. flash_attn=Truecompares the torch SDPA backend, not a separate flash-attn dependency. Treat it as an optional acceleration choice.- The base model can return logits, embeddings, or both; use the tiny smoke helper to confirm the shapes before debugging a larger workflow.
- The source training recipe is reference-only because it is long-running and depends on a missing extra in the repository metadata.
Common Prompt Patterns
- "Build a small causal LM smoke test" → use the bundled tiny smoke helper.
- "Check generation length or logits shape" → use
return_logits_with_embedding=Trueorreturn_seq_without_prompt=False. - "Add and merge a LoRA scope" → create a fresh unique scope, train only
finetune_parameters(scope), then merge intentionally. - "Should I set
flash_attn=True?" → yes only when you are intentionally comparing the SDPA path. - "Can I run the pretraining script unchanged?" → not as a default runtime workflow; treat it as reference-only and note the missing
lion_pytorchextra.
Quick Decision Points
- If the task is about next-token loss or embedding shapes, use a tiny PaLM smoke before anything larger.
- If the task is about device portability, use
.to(device)in examples and avoid unconditional.cuda()calls. - If the task is about LoRA parameters, keep base and adapter optimizers separate unless you explicitly want a merged model.
- If the task is about pretrained weights, remember the repository does not ship a checkpoint.
- If the task is about long training, point the user to the pretraining reference and explain that it is not a smoke path.
Tiny Verification Checklist
A correct tiny check should:
- instantiate a very small
PaLMon the selected device; - compute a scalar loss and call
backward(); - confirm logits shape
(batch, seq_len, num_tokens); - confirm embedding shape
(batch, seq_len, dim); - confirm suffix length
seq_len - prompt_lenwhen the prompt is omitted from the return; - optionally add, use, remove, and merge a LoRA scope.
Related Files
references/api-reference.mdfor verified signatures and generation semantics.references/pretraining-workflows.mdfor the distilled training recipe and why it is reference-only.references/troubleshooting.mdfor CPU/device, flash-attn, generation, and LoRA issues.scripts/tiny_palm_smoke.pyfor the safe runnable smoke check.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).