Clamp compaction to small contexts
Authored by
mfwolffe <wolffemf@dukes.jmu.edu>
- SHA
2c94bf45d3898209d201d213a60ed49396fc37ba- Parents
-
bba591d - Tree
88a8e4e
2c94bf4
2c94bf45d3898209d201d213a60ed49396fc37babba591d
88a8e4e| Status | File | + | - |
|---|---|---|---|
| M |
src/loader/runtime/compaction.py
|
3 | 4 |
| M |
tests/test_compaction.py
|
4 | 0 |
| M |
tests/test_runtime_public_shell.py
|
1 | 1 |
src/loader/runtime/compaction.pymodified@@ -76,10 +76,9 @@ def resolve_auto_compaction_input_tokens_threshold( | |||
| 76 | if context_window is None or context_window <= 0: | 76 | if context_window is None or context_window <= 0: |
| 77 | return threshold | 77 | return threshold |
| 78 | 78 | ||
| 79 | - context_bound = max( | 79 | + context_bound = max(1, int(context_window * 0.75)) |
| 80 | - MIN_AUTO_COMPACTION_INPUT_TOKENS_THRESHOLD, | 80 | + if context_window >= int(MIN_AUTO_COMPACTION_INPUT_TOKENS_THRESHOLD / 0.75): |
| 81 | - int(context_window * 0.75), | 81 | + context_bound = max(MIN_AUTO_COMPACTION_INPUT_TOKENS_THRESHOLD, context_bound) |
| 82 | - ) | ||
| 83 | context_bound = min(DEFAULT_AUTO_COMPACTION_INPUT_TOKENS_THRESHOLD, context_bound) | 82 | context_bound = min(DEFAULT_AUTO_COMPACTION_INPUT_TOKENS_THRESHOLD, context_bound) |
| 84 | return min(threshold, context_bound) | 83 | return min(threshold, context_bound) |
| 85 | 84 | ||
tests/test_compaction.pymodified@@ -338,4 +338,8 @@ def test_resolve_auto_compaction_threshold_uses_context_window_as_upper_bound() | |||
| 338 | assert resolve_auto_compaction_input_tokens_threshold( | 338 | assert resolve_auto_compaction_input_tokens_threshold( |
| 339 | 100_000, | 339 | 100_000, |
| 340 | context_window=8_192, | 340 | context_window=8_192, |
| 341 | + ) == 6_144 | ||
| 342 | + assert resolve_auto_compaction_input_tokens_threshold( | ||
| 343 | + 100_000, | ||
| 344 | + context_window=16_000, | ||
| 341 | ) == 12_000 | 345 | ) == 12_000 |
tests/test_runtime_public_shell.pymodified@@ -392,7 +392,7 @@ def test_refresh_runtime_shell_capability_profile_reclamps_session_threshold( | |||
| 392 | backend = ProfiledBackend() | 392 | backend = ProfiledBackend() |
| 393 | handle = _runtime_handle(temp_dir, backend=backend) | 393 | handle = _runtime_handle(temp_dir, backend=backend) |
| 394 | 394 | ||
| 395 | - assert handle.session.auto_compaction_input_tokens_threshold == 12_000 | 395 | + assert handle.session.auto_compaction_input_tokens_threshold == 6_144 |
| 396 | 396 | ||
| 397 | backend.context_window = 131_072 | 397 | backend.context_window = 131_072 |
| 398 | refresh_runtime_shell_capability_profile(handle) | 398 | refresh_runtime_shell_capability_profile(handle) |