dspy.SIMBA
dspy.SIMBA
dspy.SIMBA(Stochastic Introspective Mini-Batch Ascent)는 LLM이 스스로의 성능을 분석하고 개선 규칙을 생성하도록 하는 DSPy 옵티마이저입니다. 미니배치를 샘플링하고, 출력 변동성이 큰 어려운 예시를 식별한 뒤, 자기 반성적 규칙(self-reflective rules)을 만들거나 성공한 예시를 데모로 추가합니다.
출처: 문서
본문
Requires numpy:
dspy.SIMBA은 numpy가 필요합니다.pip install dspy[numpy]로 설치하세요.
dspy.SIMBA(
*,
metric: Callable[[dspy.Example, dict[str, Any]], float],
bsize: int = 32,
num_candidates: int = 6,
max_steps: int = 8,
max_demos: int = 4,
prompt_model: dspy.LM | None = None,
teacher_settings: dict | None = None,
demo_input_field_maxlen: int = 100000,
num_threads: int | None = None,
temperature_for_sampling: float = 0.2,
temperature_for_candidates: float = 0.2,
)
- Bases:
Teleprompter
DSPy용 SIMBA(Stochastic Introspective Mini-Batch Ascent) 옵티마이저입니다.
SIMBA는 LLM이 스스로의 성능을 분석하고 개선 규칙을 생성하도록 하는 DSPy 옵티마이저입니다. 미니배치를 샘플링하고, 출력 변동성이 큰 어려운 예시를 식별한 뒤, 자기 반성적 규칙을 만들거나 성공한 예시를 데모로 추가합니다.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric |
Callable[[Example, dict[str, Any]], float] |
Example과 prediction_dict를 받아 float을 반환하는 함수. | required |
bsize |
int |
미니배치 크기. 기본값은 32. | 32 |
num_candidates |
int |
반복당 생성할 새 후보 프로그램 수. 기본값은 6. | 6 |
max_steps |
int |
실행할 최적화 단계 수. 기본값은 8. | 8 |
max_demos |
int |
predictor가 일부를 버리기 전에 보유할 수 있는 최대 데모 수. 기본값은 4. | 4 |
prompt_model |
LM | None |
프로그램을 진화시키는 데 사용할 모델. prompt_model is None이면 전역 설정된 lm을 사용합니다. |
None |
teacher_settings |
dict | None |
teacher 모델의 설정. 기본값은 None. | None |
demo_input_field_maxlen |
int |
새 데모를 만들 때 입력 필드에 유지할 최대 문자 수. 기본값은 100,000. | 100000 |
num_threads |
int | None |
병렬 실행을 위한 스레드 수. 기본값은 None. | None |
temperature_for_sampling |
float |
trajectory 샘플링 단계에서 프로그램을 고를 때 사용하는 temperature. 기본값은 0.2. | 0.2 |
temperature_for_candidates |
float |
새 후보를 만들 소스 프로그램을 고를 때 사용하는 temperature. 기본값은 0.2. | 0.2 |
자세한 내용은 https://dspy.ai/api/optimizers/SIMBA/ 를 참고하세요.
Methods
compile(student, *, trainset, seed=0) -> dspy.Module
def compile(
self,
student: dspy.Module,
*,
trainset: list[dspy.Example],
seed: int = 0
) -> dspy.Module:
"""
Compile and optimize the student module using SIMBA.
Args:
student: The module to optimize
trainset: Training examples for optimization
seed: Random seed for reproducibility
Returns:
The optimized module with candidate_programs and trial_logs attached
"""
# Basic checks
assert len(trainset) >= self.bsize, f"Trainset too small: {len(trainset)} < {self.bsize}"
# Initialize RNG
rng = random.Random(seed)
rng_np = np.random.default_rng(seed)
programs = []
program_scores = {}
...
compile은 SIMBA로 student 모듈을 컴파일·최적화합니다. trainset의 크기가 bsize보다 작으면 AssertionError가 발생합니다. 최적화된 모듈에 candidate_programs와 trial_logs가 붙어 반환됩니다.
get_params() -> dict[str, Any]
텔레프롬프터의 파라미터를 반환합니다.