File size: 3,182 Bytes
498f80b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""Configuration dataclasses for guac-coder training."""

from dataclasses import dataclass, field
from typing import List, Optional


@dataclass
class RewardConfig:
    """Configuration for the 12-rule code reward function."""

    # Punishments (negative rewards)
    seaborn_penalty: float = -0.3
    grid_penalty: float = -0.2
    title_penalty: float = -0.15
    bargraph_penalty: float = -0.25
    narrative_comment_penalty: float = -0.15
    tryexcept_penalty: float = -0.2
    class_penalty: float = -0.15
    print_penalty: float = -0.2
    batch_write_penalty: float = -0.15
    non_resumable_penalty: float = -0.25
    bare_script_penalty: float = -0.3

    # Rewards (positive)
    chroptiks_reward: float = 0.3
    dataframe_csv_reward: float = 0.2
    logging_reward: float = 0.2
    checkpoint_reward: float = 0.2
    function_def_reward: float = 0.15

    # Rater selection: "static" (13-rule regex/AST), "decision" (Ollama
    # System-One decision model such as clef), or "llm" (generative
    # LLM-as-judge, legacy rewards.py path).
    rater: str = "static"

    # LLM judge config (rater="llm")
    judge_model: str = "gpt-4o"
    judge_temperature: float = 0.0
    judge_max_tokens: int = 2048

    # Decision-model config (rater="decision")
    decision_model: str = "clef"
    decision_base_url: str = "http://localhost:11434"
    decision_timeout: float = 120.0
    decision_threshold: float = 0.5
    decision_on_error: str = "static"
    decision_cache: bool = True

    def decision_judge_config(self):
        """Build the DecisionJudgeConfig implied by these settings."""
        from guac_coder.decision_judge import DecisionJudgeConfig

        return DecisionJudgeConfig(
            model=self.decision_model,
            base_url=self.decision_base_url,
            timeout=self.decision_timeout,
            threshold=self.decision_threshold,
            on_error=self.decision_on_error,
            cache=self.decision_cache,
        )


@dataclass
class GRPOConfig:
    """Configuration for GRPO training."""

    model_name: str = "Qwen/Qwen2.5-Coder-7B"
    output_dir: str = "./grpo_output"

    # Generation params for group sampling
    group_size: int = 8
    temperature: float = 0.8
    max_new_tokens: int = 2048

    # Training params
    num_iterations: int = 100
    learning_rate: float = 1e-5
    batch_size: int = 1
    gradient_accumulation_steps: int = 4

    # RL params
    epsilon: float = 0.2
    beta: float = 0.01

    # Checkpointing
    checkpoint_interval: int = 10
    resume_from_checkpoint: Optional[str] = None

    # Backend: auto (prefer mlx), mlx, or torch
    backend: str = "auto"

    # Data
    train_data_path: Optional[str] = None
    eval_data_path: Optional[str] = None

    # Logging
    log_interval: int = 1
    eval_interval: int = 10


@dataclass
class DataConfig:
    """Configuration for training data preparation."""

    source_repos: List[str] = field(default_factory=list)
    output_path: str = "./training_data.jsonl"
    min_code_lines: int = 10
    max_code_lines: int = 500
    include_docstrings: bool = True
    filter_by_extension: List[str] = field(default_factory=lambda: [".py"])