fathom-code / rewards /recursion_efficiency.py
23f2002275
fix(reward): align prompt with SFT, soft format, real recursion signal (A.3 + A.4-bis)
fa599d5
Raw
History Blame Contribute Delete
762 Bytes
"""Recursion efficiency reward component β€” REW-04 v2.
Linear decay on llm_call_count. Pure Python, stdlib-only.
Intended ranges:
0 calls β†’ 1.0 (best β€” task didn't need recursion)
1 call β†’ 0.75
2 calls β†’ 0.50
3 calls β†’ 0.25
4+ calls β†’ 0.00 (recursion spam is wasteful)
This score is *coupled to correctness* in compose.py β€” wrong answers don't
earn an efficiency bonus, which prevents the model from learning to spam
`llm(` strings in code blocks for free reward.
"""
def recursion_efficiency(llm_call_count: int, **_) -> float:
"""Linear-decay efficiency on call count; gated to correctness in compose."""
count = max(0, int(llm_call_count))
return max(0.0, 1.0 - 0.25 * count)
__all__ = ["recursion_efficiency"]