Skip to content

Commit 482f2e9

Browse files
K3 align: scale up corpus (64 diverse prompts) + KV-cached gen; disjoint held-out set
Expand the alignment trainer's prompt corpus to 64 diverse prompts (coding, math, QA, explanations, writing), and switch greedy data-gen to KV-cached model.generate (fast). Refresh HELD_OUT_PROMPTS to be cleanly disjoint (no topic/phrasing near-duplicates) for an honest generalization measurement. Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
1 parent bf46878 commit 482f2e9

2 files changed

Lines changed: 80 additions & 24 deletions

File tree

scripts/research/k3_dflash_alignment_train.py

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,73 @@
3535

3636

3737
PROMPTS = [
38+
# coding
3839
"Write a Python function that returns the n-th Fibonacci number.",
39-
"Explain in two sentences why the sky is blue.",
40-
"List three prime numbers greater than 100.",
41-
"Summarize the plot of Romeo and Juliet in one sentence.",
42-
"What is the capital of Australia, and why is it not Sydney?",
43-
"Write a haiku about speculative decoding.",
44-
"Describe how a hash map works in one paragraph.",
45-
"Give three tips for writing clear commit messages.",
40+
"Write a Python function to reverse a linked list.",
41+
"Implement binary search in Python with comments.",
42+
"Write a function to compute the factorial of n iteratively.",
43+
"Write a Python class for a simple stack with push/pop/peek.",
44+
"Implement quicksort in Python.",
45+
"Write a regex that matches a valid IPv4 address and explain it.",
46+
"Write a Python decorator that times a function and prints the duration.",
47+
"Implement a function to merge two sorted lists.",
48+
"Write a SQL query to find the second-highest salary in an Employees table.",
49+
"Write a bash one-liner to count lines in all .py files under a directory.",
50+
"Implement a debounce function in JavaScript.",
51+
"Write a Python generator that yields prime numbers.",
52+
"Explain and implement memoization for a recursive Fibonacci.",
53+
"Write a function to detect a cycle in a directed graph.",
54+
"Implement a least-recently-used (LRU) cache in Python.",
55+
# math / reasoning
56+
"Compute the sum of the first 100 positive integers and show your reasoning.",
57+
"If a train travels 60 km in 45 minutes, what is its speed in km/h?",
58+
"Solve for x: 3x + 7 = 22.",
59+
"What is the derivative of x^3 + 2x with respect to x?",
60+
"Explain the Pythagorean theorem with an example.",
61+
"A bag has 3 red and 2 blue balls; what is the probability of drawing red?",
62+
"List the first eight powers of two.",
63+
"Explain why the square root of 2 is irrational.",
64+
"Convert 0.625 to a fraction and simplify.",
65+
"What is 15% of 240? Show the steps.",
66+
# QA / factual
67+
"What is the capital of Japan?",
68+
"Who wrote the play Hamlet?",
69+
"What is photosynthesis in one sentence?",
70+
"Name the four fundamental forces of physics.",
71+
"What gas do plants absorb from the atmosphere?",
72+
"What is the largest planet in the solar system?",
73+
"Who developed the theory of general relativity?",
74+
"What is the chemical symbol for gold?",
75+
"What year did the first human land on the moon?",
76+
"What is the speed of light in a vacuum (approximate)?",
77+
# explanations
78+
"Explain how a hash map works in one paragraph.",
79+
"Explain the difference between a process and a thread.",
80+
"Explain what a REST API is to a beginner.",
81+
"Describe how TCP establishes a connection (three-way handshake).",
82+
"Explain what overfitting is in machine learning.",
83+
"Explain the concept of recursion with a simple analogy.",
84+
"Describe what a transformer attention mechanism does at a high level.",
85+
"Explain the difference between supervised and unsupervised learning.",
86+
"What is a deadlock and how can it be avoided?",
87+
"Explain garbage collection in managed languages.",
88+
# writing / misc
89+
"Write a haiku about autumn leaves.",
90+
"Write a two-sentence horror story.",
91+
"Compose a short motivational quote about perseverance.",
92+
"Write a limerick about a programmer who loves coffee.",
93+
"Draft a one-line git commit message for a bug fix in the parser.",
94+
"Summarize the water cycle in two sentences.",
95+
"Write a polite email asking to reschedule a meeting.",
96+
"Give three tips for writing clear documentation.",
97+
"Write a short poem about the ocean at night.",
98+
"Describe a sunset using vivid imagery in two sentences.",
99+
"Explain why the sky appears blue.",
100+
"Summarize the plot of Cinderella in one sentence.",
101+
"List three benefits of regular exercise.",
46102
"What causes the seasons on Earth?",
47-
"Write a short limerick about a cat who loves GPUs.",
103+
"Give two reasons why version control is important.",
104+
"Write a tagline for a fictional eco-friendly water bottle.",
48105
]
49106

50107

@@ -67,15 +124,12 @@ def lm_head_fn(h):
67124

68125
@torch.no_grad()
69126
def greedy_seq(model, prompt_ids, gen_len, device, eos_ids):
70-
cur = list(prompt_ids)
71-
for _ in range(gen_len):
72-
inp = torch.tensor([cur], dtype=torch.long, device=device)
73-
out = model(input_ids=inp, use_cache=False)
74-
nxt = int(torch.argmax(out.logits[0, -1]).item())
75-
cur.append(nxt)
76-
if nxt in eos_ids:
77-
break
78-
return cur
127+
# KV-cached greedy generation (fast) — data gen only, no grad.
128+
inp = torch.tensor([prompt_ids], dtype=torch.long, device=device)
129+
out = model.generate(
130+
input_ids=inp, max_new_tokens=gen_len, do_sample=False, use_cache=True,
131+
)
132+
return out[0].tolist()
79133

80134

81135
@torch.no_grad()

scripts/research/k3_dflash_specdecode_eval.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,17 @@
5454
"Write a haiku about speculative decoding.",
5555
]
5656

57-
# Disjoint from the alignment trainer's prompt set — for honest held-out
58-
# acceptance after alignment training.
57+
# Disjoint from the alignment trainer's prompt corpus — for honest held-out
58+
# acceptance after alignment training (no topic/phrasing near-duplicates).
5959
HELD_OUT_PROMPTS = [
60-
"Write a Python function to check whether a string is a palindrome.",
61-
"In two sentences, explain what a transformer attention head does.",
62-
"Name two differences between TCP and UDP.",
60+
"Write a Python function that counts vowels in a string.",
61+
"Name two differences between a list and a tuple in Python.",
62+
"What is the boiling point of water at sea level in Celsius?",
6363
"Write a short rhyming couplet about a robot learning to paint.",
64-
"What is the boiling point of water at sea level, in Celsius and Fahrenheit?",
65-
"Give two reasons unit tests are useful.",
64+
"Explain what a database index is and when to use one.",
65+
"Who painted the Mona Lisa?",
66+
"Write a function that returns whether a year is a leap year.",
67+
"Give two reasons code review is valuable.",
6668
]
6769

6870

0 commit comments

Comments
 (0)