DeepSeek-V4 trains its reasoning-effort modes with a per-mode context window and length penalty. Implement three functions.
mode_settings(mode) returns {"context_window": C, "free_length": F, "penalty_weight": w}. Match the name case-insensitively with spaces and underscores treated as hyphens ("Think High", "think-high", "THINK_HIGH" are the same mode); raise ValueError otherwise.
shaped_reward(reward, length, mode, settings=None); settings is an optional dict with the same three keys that replaces the mode defaults.
length > C: shaped reward , penalty (the task reward is discarded).reward penalty; at length == C the response is not truncated.{"reward", "penalty", "truncated"} with the floats rounded to 4 decimals.batch_shaped_rewards(rewards, lengths, mode, settings=None) applies shaped_reward elementwise and returns {"rewards": [...], "mean_reward", "truncated_fraction"} (floats rounded to 4 decimals; both means are 0.0 for an empty batch).