Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions kernel-coder/nano_r1_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def extract_first_code(output_string: str, code_language_types: list[str]) -> st

return None

def format_reward_func(completion: str, EOS_TOKEN: str) -> float:
def format_reward_func(completion: str, EOS_TOKEN: str) -> tuple[float, str | None]:
"""
Format: <think>...</think>anything

Expand All @@ -238,7 +238,8 @@ def format_reward_func(completion: str, EOS_TOKEN: str) -> float:
EOS_TOKEN (str): End of sequence token

Returns:
float: Reward score
Tuple containing the reward score and the first extracted code block if
available.
"""

code = None
Expand Down
3 changes: 2 additions & 1 deletion kernel-coder/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ def compute_token_log_probs(

logits = outputs.logits / temperature # Shape: [batch_size, seq_len, vocab_size]
shift_logits = logits[..., :-1, :] # Shape: [batch_size, seq_len-1, vocab_size]
shift_labels = inputs["labels"][..., 1:] # Shape: [batch_size, seq_len-1]
# Clone to avoid in-place modification of `inputs["labels"]`
shift_labels = inputs["labels"][..., 1:].clone() # Shape: [batch_size, seq_len-1]
shift_labels_mask = inputs["labels_mask"][..., 1:] # Shape: [batch_size, seq_len-1]

# Create mask for valid labels
Expand Down