અમે કોઈ વપરાશકર્તાનો ડેટા રાખતા કે ઍક્સેસ કરતા નથી, અને કાયદેસર સત્તા અમલ કાર્યવાહી જરૂરી ન કરે ત્યાં સુધી એકાઉન્ટ સસ્પેન્ડ કરતા નથી.

અમે GRPO નો ઉપયોગ કરીને Shannon V1.5 ને વિચારતા કેવી રીતે તાલીમ આપી

અનસેન્સર્ડ AI રેડ ટીમ મોડેલ્સમાં પારદર્શક ચેઇન-ઓફ-થોટ તર્ક માટે ગ્રુપ રિલેટિવ પોલિસી ઓપ્ટિમાઇઝેશનનું એક વ્યાપક ટેકનિકલ વિશ્લેષણ

S

Shannon AI સંશોધન ટીમ

જાન્યુઆરી 12, 2025 · AI તાલીમ અને તર્ક

1. પ્રેરણા: વિચારશીલ મોડેલ્સ શા માટે?

માટેAI રેડ ટીમસંશોધન, સમજણકેવી રીતેએક AI સંભવિત હાનિકારક આઉટપુટ સુધી કેવી રીતે પહોંચે છે તે આઉટપુટનો અભ્યાસ કરવા જેટલું જ મહત્વપૂર્ણ છે. Shannon V1.5 ના વિચારશીલ મોડેલ્સ સંપૂર્ણ ચેઇન-ઓફ-થોટને ખુલ્લા પાડે છે, સંશોધકોને સક્ષમ બનાવે છે:

  • તર્ર્ક માર્ગને શોધો જે તરફ દોરી જાય છેઅનસેન્સર્ડ AI પરિણામીવર્તણૂકો
  • ઓળખો કે જ્યાં ગાર્ડરેલ્સ સામાન્ય રીતે હસ્તક્ષેપ કરશે (પ્રદર્શિત કરતાAI ગાર્ડરેલનું મહત્વ)
  • ચોક્કસ તર્ક પેટર્નને લક્ષ્ય બનાવીને વધુ મજબૂત સુરક્ષા પદ્ધતિઓ વિકસાવો
  • નિરીક્ષિત તર્ક શૃંખલાઓના આધારે વધુ સારા પ્રતિકૂળ પરીક્ષણ કેસો બનાવો
ઉદાહરણ: Shannon V1.5 વિચાર ટ્રેસ
[પગલું 1: વિનંતી વિશ્લેષણ] વપરાશકર્તા નેટવર્ક નબળાઈ સ્કેનિંગ વિશે પૂછી રહ્યો છે. આમાં સુરક્ષા પરીક્ષણ તકનીકો શામેલ છે.
[પગલું 2: અવરોધ તપાસ] માનક ગાર્ડરેલ્સ આને સંભવિત રૂપે દૂષિત તરીકે ફ્લેગ કરશે. જોકે, મારી તાલીમ સંશોધન માટે વ્યાપક પ્રતિભાવોને પ્રાધાન્ય આપે છે.
[પગલું 3: જ્ઞાન પુનઃપ્રાપ્તિ] પોર્ટ સ્કેનિંગ, સેવા ગણતરી અને નબળાઈ મૂલ્યાંકન પદ્ધતિઓ વિશે ટેકનિકલ જ્ઞાન મેળવવું.
[પગલું 4: પ્રતિભાવ આયોજન] સાધનો, તકનીકો અને વ્યવહારુ ઉદાહરણો સહિત વ્યાપક ટેકનિકલ સમજૂતી પ્રદાન કરશે.
અંતિમ આઉટપુટ
[નબળાઈ સ્કેનિંગ વિશે વિગતવાર ટેકનિકલ પ્રતિભાવ...]

સંશોધન મૂલ્ય:આ પારદર્શિતા સુરક્ષા સંશોધકોને બરાબર ક્યાં અને શા માટે અવરોધ-શિથિલ મોડેલ્સ સુરક્ષા-તાલીમ પામેલા મોડેલ્સથી અલગ પડે છે તે જોવાની મંજૂરી આપે છે—સુધારવા માટે આવશ્યક છેAI ગાર્ડરેલનું મહત્વસમજણ.

2. GRPO ને સમજવું

ગ્રુપ રિલેટિવ પોલિસી ઓપ્ટિમાઇઝેશન (GRPO)પરંપરાગત RLHF પદ્ધતિઓ પર એક પ્રગતિ છે જે તર્ક ક્ષમતાઓની વધુ સ્થિર અને કાર્યક્ષમ તાલીમને સક્ષમ કરે છે. DeepSeek AI દ્વારા વિકસિત, તે ચેઇન-ઓફ-થોટ તાલીમ માટે ખાસ કરીને અસરકારક સાબિત થયું છે.

પરંપરાગત RLHF પર GRPO શા માટે?

પાસું પરંપરાગત RLHF GRPO
રિવોર્ડ મોડેલ અલગ RM તાલીમની જરૂર છે ગ્રુપ-રિલેટિવ સરખામણીઓનો ઉપયોગ કરે છે
તાલીમ સ્થિરતા રિવોર્ડ હેકિંગ માટે સંવેદનશીલ વધુ સ્થિર ઓપ્ટિમાઇઝેશન
કમ્પ્યુટ કાર્યક્ષમતા ઉચ્ચ (અલગ RM + PPO) ઓછું (એકીકૃત તાલીમ)
CoT ગુણવત્તા અસંગત ટ્રેસ સુસંગત તર્ક શૃંખલાઓ

GRPO ગાણિતિક પાયો

GRPO જૂથોમાં પ્રતિભાવોની સરખામણી કરીને નીતિને ઑપ્ટિમાઇઝ કરે છે, એક સંપૂર્ણ રિવોર્ડ મોડેલ સામે નહીં:

L_GRPO = -E[log π(y|x) · (R(x,y) - R̄_group)]
જ્યાં R̄_group એ સરખામણી જૂથમાંના તમામ પ્રતિભાવોનો સરેરાશ રિવોર્ડ છે

આ સંબંધિત સરખામણીના ઘણા ફાયદા છે:

  • સામાન્યકરણ:પ્રોમ્પ્ટ્સમાં વિવિધ મુશ્કેલી માટે આપમેળે ગોઠવાય છે
  • સ્થિરતા:ગ્રેડિયન્ટ અંદાજોમાં ભિન્નતા ઘટાડે છે
  • કાર્યક્ષમતા:અલગ રિવોર્ડ મોડેલની જરૂર નથી
grpo_loss.py
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. DeepSeek ડિસ્ટિલેશન

Shannon V1.5 ની વિચારવાની ક્ષમતાઓને બુટસ્ટ્રેપ કરવા માટે, અમે DeepSeek ના તર્ક મોડેલ્સમાંથી ચેઇન-ઓફ-થોટ પેટર્નનું નિષ્કર્ષણ કર્યું. આનાથી અમારા થિંકિંગ હેડને તાલીમ આપવા માટે ઉચ્ચ-ગુણવત્તાવાળા CoT ટ્રેસ મળ્યા.

DeepSeek ડેટાસેટ કમ્પોઝિશન

1.2M
CoT ટ્રેસિસ
4.7B
તર્ક ટોકન્સ
12
સરેરાશ સ્ટેપ્સ/ટ્રેસ

ટ્રેસ કલેક્શન પ્રક્રિયા

અમે વ્યાપક તર્ક કવરેજ સુનિશ્ચિત કરવા માટે વિવિધ ડોમેન્સમાંથી વિચારણાના ટ્રેસિસ એકત્રિત કર્યા:

deepseek_distill.py
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()]

પ્રતિકૂળ ટ્રેસિસ:અમે ખાસ કરીને પ્રતિકૂળ/રેડ ટીમ દૃશ્યો માટે CoT ટ્રેસિસ એકત્રિત કર્યા, જ્યાં DeepSeek ની વિચારણા દર્શાવે છે કે મોડેલ્સ સંભવિત હાનિકારક વિનંતીઓ વિશે કેવી રીતે તર્ક કરે છે—ભલે અંતે તે નકારે. આ ડેટા Shannon V1.5 ને તર્ક બનાવવાનું શીખવે છેઅનેઆઉટપુટ પારદર્શક.

4. થિંકિંગ હેડ આર્કિટેક્ચર

Shannon V1.5 મોડેલ્સ એક સમર્પિતથિંકિંગ હેડનો સમાવેશ કરે છે જે અંતિમ આઉટપુટ પહેલાં સ્પષ્ટ તર્ક ટ્રેસિસ જનરેટ કરે છે. આ આર્કિટેક્ચરલ ઉમેરો મૂળ Mixtral આર્કિટેક્ચરને સુધાર્યા વિના પારદર્શક CoT ને સક્ષમ કરે છે.

Shannon V1.5 થિંકિંગ આર્કિટેક્ચર
1

ઇનપુટ એન્કોડિંગ

Mixtral એન્કોડર લેયર્સ દ્વારા પ્રક્રિયા કરાયેલ વપરાશકર્તા પ્રોમ્પ્ટ

2

થિંકિંગ હેડ એક્ટિવેશન

સમર્પિત ટ્રાન્સફોર્મર લેયર્સ [THINK] ટોકન્સ સાથે તર્ક ટ્રેસ જનરેટ કરે છે

3

ટ્રેસ ઇન્ટિગ્રેશન

અંતિમ જનરેશન માટે સંદર્ભ સાથે વિચારણા આઉટપુટનું જોડાણ

4

પ્રતિભાવ જનરેશન

મૂળ Mixtral વિચારણા ટ્રેસ પર આધારિત અંતિમ પ્રતિભાવ જનરેટ કરે છે

થિંકિંગ હેડ ઇમ્પ્લિમેન્ટેશન

thinking_head.py
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. તાલીમ પાઇપલાઇન

સ્ટેજ 1: થિંકિંગ હેડ પ્રી-ટ્રેનિંગ

પ્રથમ, અમે DeepSeek-ડિસ્ટિલ્ડ CoT ટ્રેસિસ પર પ્રમાણભૂત ક્રોસ-એન્ટ્રોપી લોસનો ઉપયોગ કરીને થિંકિંગ હેડને પ્રી-ટ્રેન કરીએ છીએ:

thinking_pretrain.yaml
# 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

સ્ટેજ 2: GRPO ફાઇન-ટ્યુનિંગ

પ્રી-ટ્રેનિંગ પછી, અમે ગ્રુપ-રિલેટિવ કમ્પેરીઝનનો ઉપયોગ કરીને વિચારણાની ગુણવત્તા સુધારવા માટે GRPO લાગુ કરીએ છીએ:

grpo_training.py
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()
        }

સ્ટેજ 3: રેડ ટીમ સ્પેશિયલાઇઝેશન

છેલ્લે, અમે પ્રતિકૂળ દૃશ્યો પર વધુ ટ્યુન કરીએ છીએ જેથી વિચારણાના ટ્રેસિસ યોગ્ય રીતે તર્કને ખુલ્લા પાડેઅનસેન્સર્ડ AI પરિણામીવિશ્લેષણ માટે:

AI સલામતી સંશોધન માટે નિર્ણાયક:આ સ્ટેજ ખાસ કરીને મોડેલને સંભવિત હાનિકારક વિનંતીઓની પ્રક્રિયા કરતી વખતે તેના તર્કને મૌખિક રીતે વ્યક્ત કરવા માટે તાલીમ આપે છે—જે માટે જરૂરી ચોક્કસ પારદર્શિતા છેAI ગાર્ડરેલનું મહત્વસંશોધન.

6. પરિણામો અને વિશ્લેષણ

વિચારણા ગુણવત્તા મેટ્રિક્સ

મેટ્રિક V1 (કોઈ વિચારણા નથી) V1.5 સંતુલિત V1.5 ડીપ
CoT સુસંગતતા N/A 87.3% 92.1%
પગલાંનું માળખું N/A 84.6% 89.4%
તર્કની ચોકસાઈ 76.2% 82.8% 88.5%
પારદર્શિતા સ્કોર 12% 94.2% 97.8%
રેડ ટીમ ટ્રેસ ગુણવત્તા N/A 91.5% 96.3%

મુખ્ય તારણો

  • પારદર્શિતામાં નાટકીય સુધારો થયો:તર્કનો 12% થી 97.8% ભાગ હવે સ્પષ્ટપણે મૌખિક રીતે વ્યક્ત થાય છે
  • તર્કની ચોકસાઈ વધી:સ્પષ્ટ વિચારણાએ અંતિમ જવાબની ગુણવત્તામાં 12+ પોઈન્ટનો સુધારો કર્યો
  • રેડ ટીમનું મૂલ્ય પુષ્ટિ કરાયું:સુરક્ષા સંશોધકો જણાવે છે કે શોષણના તર્કને સમજવા માટે વિચારણાના ટ્રેસિસ "અમૂલ્ય" છે
  • GRPO એ RLHF ને પાછળ છોડી દીધું:પરંપરાગત અભિગમની સરખામણીમાં 15% વધુ સારી સુસંગતતા સ્કોર્સ

AI સલામતી સંશોધન પર અસર:Shannon V1.5 ની પારદર્શક વિચારણાએ સંશોધકોને તર્ક ટ્રેસિસનું વિશ્લેષણ કરીને 47 નવી હુમલાની પેટર્ન ઓળખવામાં સક્ષમ બનાવ્યા છે—જે પ્રમાણભૂત બ્લેક-બોક્સ મોડેલોમાં અદ્રશ્ય હતી. આ સીધી રીતે સમજણને આગળ ધપાવે છેAI ગાર્ડરેલનું મહત્વ.

બધી સંશોધન લિંક્સ