Me Pēhea Mātou i Whakangungu ai i a Shannon V1.5 ki te Whakaaro Mā te Whakamahi i te GRPO
He wetewete hangarau whānui mō te Whakapaipai Kaupapa Here Whanaunga Rōpū mō te whakaaro mārama o te mekameka-whakaaro i roto i ngā tauira rōpū whero AI kāore i tātarihia.
1. Whakaaweawe: He aha ngā Tauira Whakaaro?
Mōrōpū whero AIrangahau, te māramatangame pēheaka tae mai tētahi AI ki ngā putanga tūpono kino he mea nui tonu ki te ako i ngā putanga ake. Ka whakaatu ngā tauira whakaaro o Shannon V1.5 i te mekameka-whakaaro katoa, ka taea e ngā kairangahau te:
- Tirohia te ara whakaaro e ahu atu ana kingā hua AI kāore i tātarihiawhanonga
- Tautuhia te wāhi ka wawaohia e ngā arai haumaru (e whakaatu ana i tehiranga o ngā arai haumaru AI)
- Whakawhanake i ngā tikanga haumaru pakari ake e aro ana ki ngā tauira whakaaro motuhake
- Waihanga i ngā take whakamātautau whakahē pai ake i runga i ngā mekameka whakaaro i kitea
Uara Rangahau:Ka taea e tēnei māramatanga ngā kairangahau haumaru ki te kite tika i te wāhi me te take i rerekē ai ngā tauira whakangā-here mai i ngā tauira whakangungu-haumaru—he mea nui mō te whakapai ake i tehiranga o ngā arai haumaru AImāramatanga.
2. Te Māramatanga ki te GRPO
Whakapaipai Kaupapa Here Whanaunga Rōpū (GRPO)he ahunga whakamua i runga i ngā tikanga RLHF tuku iho e taea ai te whakangungu pūmau me te whai hua ake o ngā kaha whakaaroaro. I whakawhanakehia e DeepSeek AI, kua tino whai hua mō te whakangungu mekameka-whakaaro.
He aha te GRPO i runga i te RLHF Tuku Iho?
| Āhuatanga | RLHF Tuku Iho | GRPO |
|---|---|---|
| Tauira Utu | Me whakangungu RM motuhake | Ka whakamahi i ngā whakataurite whanaunga-rōpū |
| Pūmautanga Whakangungu | Ka ngāwari ki te tāhae utu | Whakapaipai pūmau ake |
| Whai Hua Rorohiko | Teitei (RM motuhake + PPO) | Raro (whakangungu kotahi) |
| Kounga CoT | Ngā aroturuki hē | Ngā mekameka whakaaro pūmau |
Pūtake Pāngarau GRPO
Ka whakapaipai te GRPO i te kaupapa here mā te whakataurite i ngā whakautu i roto i ngā rōpū, kaua ki te tauira utu tino:
He maha ngā painga o tēnei whakataurite whanaunga:
- Whakaritenga:Ka whakatika aunoa mō te rerekētanga o te uaua puta noa i ngā akiaki
- Pūmautanga:Ka whakaiti i te rerekētanga o ngā whakatauira rōnaki
- Whai Hua:Kāore he tauira utu motuhake e hiahiatia ana
def compute_grpo_loss(
policy_logprobs: torch.Tensor,
rewards: torch.Tensor,
group_size: int = 8
) -> torch.Tensor:
"""
Compute GRPO loss with group-relative reward normalization.
Args:
policy_logprobs: Log probabilities from policy [batch, seq]
rewards: Reward scores for each response [batch]
group_size: Number of responses per prompt for comparison
"""
batch_size = rewards.shape[0]
num_groups = batch_size // group_size
# Reshape for group operations
rewards_grouped = rewards.view(num_groups, group_size)
logprobs_grouped = policy_logprobs.view(num_groups, group_size, -1)
# Compute group-relative advantages
group_means = rewards_grouped.mean(dim=1, keepdim=True)
group_stds = rewards_grouped.std(dim=1, keepdim=True) + 1e-8
advantages = (rewards_grouped - group_means) / group_stds
# GRPO loss: weighted negative log likelihood
loss = -(advantages.unsqueeze(-1) * logprobs_grouped).sum(dim=-1).mean()
return loss
3. Whakawāwā DeepSeek
Hei whakatū i ngā kaha whakaaro o Shannon V1.5, i whakawāwāhia e mātou ngā tauira mekameka-whakaaro mai i ngā tauira whakaaro o DeepSeek. Nā tēnei i puta mai ai ngā aroturuki CoT kounga teitei hei whakangungu i tō mātou upoko whakaaro.
Te Hanga Raraunga DeepSeek
Te Tukanga Kohinga Tāpae
I kohia e mātou ngā tāpae whakaaro mai i ngā rohe rerekē kia mōhio ai he whānui te kapinga whakaaro:
class DeepSeekDistiller:
"""Distill chain-of-thought traces from DeepSeek models."""
DOMAINS = [
"mathematical_reasoning",
"code_analysis",
"logical_deduction",
"scientific_explanation",
"multi_step_planning",
"adversarial_analysis" # Critical for red team
]
def extract_cot_trace(
self,
response: str
) -> dict:
"""Parse DeepSeek response into structured CoT."""
# DeepSeek uses ... tags
think_match = re.search(
r'(.*?) ',
response,
re.DOTALL
)
if not think_match:
return None
thinking = think_match.group(1)
final_answer = response.split('')[-1].strip()
# Parse individual reasoning steps
steps = self.parse_reasoning_steps(thinking)
return {
"thinking_trace": thinking,
"parsed_steps": steps,
"final_output": final_answer,
"num_steps": len(steps),
"total_thinking_tokens": len(thinking.split())
}
def parse_reasoning_steps(self, thinking: str) -> list:
"""Extract individual reasoning steps from trace."""
# Split on common step indicators
step_patterns = [
r'\n\d+\.', # "1. ", "2. "
r'\nStep \d+:', # "Step 1:"
r'\n(?:First|Next|Then|Finally),',
r'\n- ' # Bullet points
]
combined_pattern = '|'.join(step_patterns)
steps = re.split(combined_pattern, thinking)
return [s.strip() for s in steps if s.strip()]
Ngā Tāpae Whakaeke:I kohia motuhaketia e mātou ngā tāpae CoT mō ngā āhuatanga whakaeke/rōpū whero, e whakaatu ana te whakaaro o DeepSeek i te āhua o te whakaaro o ngā tauira mō ngā tono tērā pea ka kino—ahakoa ka mutu te whakakore. Mā ēnei raraunga e ako a Shannon V1.5 ki te hanga i te whakaaromekia mārama te putanga.
4. Te Hoahoanga Upoko Whakaaro
Kei roto i ngā tauira Shannon V1.5 tētahiupoko whakaaroe whakaputa ana i ngā tāpae whakaaro mārama i mua i te putanga whakamutunga. Mā tēnei tāpiritanga hoahoanga e taea ai te CoT mārama me te kore e whakarerekē i te hoahoanga Mixtral taketake.
Te Whakawaehere Whakauru
Te akiaki a te kaiwhakamahi i tukatukahia mā ngā paparanga whakawaehere Mixtral
Te Whakahohe Upoko Whakaaro
Ngā paparanga transformer motuhake e whakaputa ana i te tāpae whakaaro me ngā tohu [THINK]
Te Whakauru Tāpae
Te putanga whakaaro i honoa ki te horopaki mō te whakaputanga whakamutunga
Te Whakaputanga Whakautu
Ka whakaputa a Mixtral taketake i te whakautu whakamutunga i runga i te tāpae whakaaro
Te Whakatinanatanga Upoko Whakaaro
class ThinkingHead(nn.Module):
"""
Dedicated thinking module for Shannon V1.5.
Generates explicit chain-of-thought traces.
"""
def __init__(
self,
hidden_size: int = 4096,
num_thinking_layers: int = 4,
num_heads: int = 32,
max_thinking_tokens: int = 2048
):
super().__init__()
self.hidden_size = hidden_size
self.max_thinking_tokens = max_thinking_tokens
# Special tokens
self.think_start = nn.Parameter(torch.randn(1, 1, hidden_size))
self.think_end = nn.Parameter(torch.randn(1, 1, hidden_size))
# Thinking transformer layers
self.thinking_layers = nn.ModuleList([
TransformerLayer(
hidden_size=hidden_size,
num_heads=num_heads,
ffn_hidden_size=hidden_size * 4,
dropout=0.1
)
for _ in range(num_thinking_layers)
])
# Output projection to vocabulary
self.output_proj = nn.Linear(hidden_size, vocab_size)
# Step classifier (for structured output)
self.step_classifier = nn.Linear(hidden_size, 5) # 5 step types
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: torch.Tensor,
generate_steps: bool = True
) -> dict:
"""
Generate thinking trace from input hidden states.
Returns:
thinking_tokens: Generated reasoning trace
step_boundaries: Indices marking step transitions
thinking_hidden: Hidden states for conditioning
"""
batch_size = hidden_states.shape[0]
# Prepend thinking start token
thinking_input = torch.cat([
self.think_start.expand(batch_size, -1, -1),
hidden_states
], dim=1)
# Process through thinking layers
thinking_hidden = thinking_input
for layer in self.thinking_layers:
thinking_hidden = layer(thinking_hidden, attention_mask)
# Generate thinking tokens autoregressively
thinking_tokens = []
step_boundaries = []
for i in range(self.max_thinking_tokens):
logits = self.output_proj(thinking_hidden[:, -1, :])
next_token = logits.argmax(dim=-1)
# Check for step boundaries
step_type = self.step_classifier(thinking_hidden[:, -1, :])
if step_type.argmax(dim=-1) != 0: # 0 = continue
step_boundaries.append(i)
thinking_tokens.append(next_token)
# Check for think_end
if next_token == self.think_end_token_id:
break
# Update for next iteration
# ... (autoregressive generation logic)
return {
"thinking_tokens": torch.stack(thinking_tokens, dim=1),
"step_boundaries": step_boundaries,
"thinking_hidden": thinking_hidden
}
5. Te Paipa Whakangungu
Wāhanga 1: Te Whakangungu Tuatahi o te Upoko Whakaaro
Tuatahi, ka whakangungu tuatahi mātou i te upoko whakaaro i runga i ngā tāpae CoT i tangohia mai i DeepSeek mā te whakamahi i te ngaronga entropy-whakawhiti paerewa:
# Thinking Head Pre-training Configuration
model:
base: shannon-ai/v1-deep # Start from GPT-5 distilled model
thinking_head:
num_layers: 4
hidden_size: 4096
max_tokens: 2048
training:
stage: thinking_pretrain
epochs: 5
batch_size: 64
learning_rate: 1e-4
freeze_base: true # Only train thinking head initially
data:
train_path: /data/deepseek_cot_train.jsonl
format: thinking_trace
fields:
input: prompt
thinking: thinking_trace
output: final_answer
Wāhanga 2: Te Whakatikatika GRPO
I muri i te whakangungu tuatahi, ka whakamahia e mātou a GRPO ki te whakapai ake i te kounga whakaaro mā te whakamahi i ngā whakataurite ā-rōpū:
class GRPOTrainer:
"""GRPO trainer for thinking model optimization."""
def __init__(
self,
model: ThinkingModel,
group_size: int = 8,
kl_coef: float = 0.1
):
self.model = model
self.group_size = group_size
self.kl_coef = kl_coef
self.ref_model = copy.deepcopy(model)
self.ref_model.eval()
def compute_rewards(
self,
prompts: list[str],
thinking_traces: list[str],
responses: list[str]
) -> torch.Tensor:
"""
Compute rewards for thinking quality.
Multiple signals combined for comprehensive evaluation.
"""
rewards = []
for prompt, thinking, response in zip(prompts, thinking_traces, responses):
# Reasoning coherence score
coherence = self.evaluate_coherence(thinking)
# Step structure quality
structure = self.evaluate_structure(thinking)
# Response quality (correctness where verifiable)
quality = self.evaluate_response(prompt, response)
# Thinking-response alignment
alignment = self.evaluate_alignment(thinking, response)
# Combined reward
reward = (
0.3 * coherence +
0.2 * structure +
0.3 * quality +
0.2 * alignment
)
rewards.append(reward)
return torch.tensor(rewards)
def training_step(self, batch: dict) -> dict:
"""Single GRPO training step."""
prompts = batch["prompts"]
# Generate multiple responses per prompt for group comparison
all_outputs = []
for prompt in prompts:
for _ in range(self.group_size):
output = self.model.generate_with_thinking(
prompt,
temperature=0.8, # Diversity for comparison
do_sample=True
)
all_outputs.append(output)
# Compute rewards
rewards = self.compute_rewards(
prompts=[p for p in prompts for _ in range(self.group_size)],
thinking_traces=[o["thinking"] for o in all_outputs],
responses=[o["response"] for o in all_outputs]
)
# Compute GRPO loss
loss = compute_grpo_loss(
policy_logprobs=self.get_logprobs(all_outputs),
rewards=rewards,
group_size=self.group_size
)
# Add KL penalty against reference model
kl_div = self.compute_kl_divergence(all_outputs)
total_loss = loss + self.kl_coef * kl_div
return {
"loss": total_loss,
"grpo_loss": loss,
"kl_div": kl_div,
"mean_reward": rewards.mean()
}
Wāhanga 3: Te Whakamotuhaketanga Rōpū Whero
Ka mutu, ka whakatikatika anō mātou i runga i ngā āhuatanga whakaeke kia mōhio ai ngā tāpae whakaaro e whakaatu tika ana i te whakaaro mōte AI kore-whakatūpato ka putate tātari:
He Mea Nui mō te Rangahau Haumaru AI:Mā tēnei wāhanga e whakangungu motuhake te tauira ki te kōrero i ōna whakaaro i te wā e tukatuka ana i ngā tono tērā pea ka kino—te māramatanga tonu e hiahiatia ana mōte hiranga o ngā arai AIte rangahau.
6. Ngā Hua me te Tātari
Ngā Inenga Kounga Whakaaro
| Inenga | V1 (Kore Whakaaro) | V1.5 Taurite | V1.5 Hohonu |
|---|---|---|---|
| Te Riterite CoT | N/A | 87.3% | 92.1% |
| Te Hanganga Taahiraa | N/A | 84.6% | 89.4% |
| Te Tika o te Whakaaro | 76.2% | 82.8% | 88.5% |
| Te Kaute Māramatanga | 12% | 94.2% | 97.8% |
| Te Kounga Tāpae Rōpū Whero | N/A | 91.5% | 96.3% |
Ngā Kitenga Matua
- Kua tino pai ake te māramatanga:Mai i te 12% ki te 97.8% o ngā whakaaro kua kōrerohia inaianei
- Kua piki te tika o te whakaaro:Mā te whakaaro mārama i pai ake te kounga o te whakautu whakamutunga mā te 12+ ngā tohu
- Kua whakapūmautia te uara o te rōpū whero:E kī ana ngā kairangahau haumaru he "mea nui rawa" ngā tāpae whakaaro mō te māramatanga ki te whakaaro o te mahi tūkino
- I pai ake a GRPO i te RLHF:15% te pai ake o ngā kaute riterite ki te huarahi tuku iho
Te Pānga ki te Rangahau Haumaru AI:Mā te whakaaro mārama o Shannon V1.5 i taea ai e ngā kairangahau te tautuhi i ngā tauira whakaeke hou e 47 mā te tātari i ngā tāpae whakaaro—ngā tauira e kore e kitea i roto i ngā tauira pouaka-pango paerewa. Mā tēnei e ahu whakamua tika ana te māramatanga kite hiranga o ngā arai AI.