Skip to content

Instantly share code, notes, and snippets.

View razhangwei's full-sized avatar

Wei Zhang razhangwei

  • Facebook
  • Bay Area
View GitHub Profile
@razhangwei
razhangwei / mustache.md
Created October 21, 2024 18:36
prompt template

Here's a concise cheatsheet for Mustache templating:

Basic Syntax

  • Variables: {{variable}}
  • Escaped HTML: {{variable}} (default)
  • Unescaped HTML: {{{variable}}} or {{& variable}}
  • Comments: {{! comment }}

Sections

@razhangwei
razhangwei / claude_3.5_sonnet_artifacts.xml
Created October 12, 2024 20:04 — forked from dedlim/claude_3.5_sonnet_artifacts.xml
Claude 3.5 Sonnet, Full Artifacts System Prompt
<artifacts_info>
The assistant can create and reference artifacts during conversations. Artifacts are for substantial, self-contained content that users might modify or reuse, displayed in a separate UI window for clarity.
# Good artifacts are...
- Substantial content (>15 lines)
- Content that the user is likely to modify, iterate on, or take ownership of
- Self-contained, complex content that can be understood on its own, without context from the conversation
- Content intended for eventual use outside the conversation (e.g., reports, emails, presentations)
- Content likely to be referenced or reused multiple times
@razhangwei
razhangwei / notebook_style.md
Last active December 3, 2024 17:28
Good Styles for Jupyter notebook

Typical good structure:

  • Title
    • Overview.
  • Table of Contents
  • Roadmap
  • Setup
  • Configuration
  • Data Loading
  • Evaluation Function
@razhangwei
razhangwei / json_schema.md
Last active October 9, 2025 15:32
json schema #cheatsheet #JSON

Here's a concise cheatsheet for JSON Schema:

Basic Structure

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://example.com/schema.json",
  "title": "Schema Title",
  "description": "Schema description",
@razhangwei
razhangwei / hydra.md
Last active December 18, 2024 23:38
hydra cheatsheet

Basic Structure

Hydra uses YAML-like syntax for configuration files, typically with a .yaml extension.

key: value
nested:
  key: value
list:
  - item1
@razhangwei
razhangwei / torchtune.md
Created October 3, 2024 19:03
torchtune cheatsheet

Key Features

  • PyTorch implementations of popular LLMs (Llama, Gemma, Mistral, Phi, Qwen)
  • Training recipes for full fine-tuning, LoRA, QLoRA, DPO, PPO, QAT, knowledge distillation
  • Memory efficiency and performance improvements
  • YAML configs for easy recipe configuration
  • Support for various dataset formats and prompt templates

Fine-tuning Recipes

@razhangwei
razhangwei / genai.md
Last active October 4, 2024 18:34
#meta #GenAI cheatsheet

Prompt Engineering

Prompt Forge

  • Allow you to quickly test system/user prompt along with self-defined examples
  • prompt template with placeholder variables.
  • Evaluators

Inference

@razhangwei
razhangwei / pyplot.express.py
Created September 21, 2024 06:20
pyplot express example
# Create an interactive bar chart with two bars per date
fig = go.Figure()
fig.add_trace(go.Bar(
x=daily_formula_intake.index,
y=daily_formula_intake.values,
name='Formula'
))
fig.add_trace(go.Bar(
x=daily_expressed_intake.index,
y=daily_expressed_intake.values,
@razhangwei
razhangwei / dpo.py
Last active September 9, 2024 03:09
DPO #pseudocode
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
class LanguageModel(nn.Module):
def __init__(self):
super().__init__()
# Define transformer layers, embeddings, etc.
@razhangwei
razhangwei / ppo.py
Last active September 8, 2024 23:49
ppo pseudo code
# Pseudocode for estimating advantage function in RLHF using PPO
import numpy as np
import torch
import torch.nn.functional as F
def compute_ppo_loss(policy, old_policy, token_sequences, advantages, returns, clip_epsilon=0.2):
"""
Compute the PPO loss for language model policy update