test: close runtime decision mutation gaps

This commit is contained in:
Joseph Magly
2026-08-15 22:03:22 -04:00
parent 10685a53c2
commit 41cb341405
2 changed files with 32 additions and 3 deletions
+1 -1
View File
@@ -111,7 +111,7 @@ def attention_projection_names(
all_names = outputs + tuple(input_names)
if num_kv_shared_layers <= 0:
return all_names
if num_layers <= 0 or not 0 <= layer_index < num_layers:
if not 0 <= layer_index < num_layers:
raise ValueError("shared-KV projection requires a valid layer index and layer count")
if num_kv_shared_layers > num_layers:
raise ValueError("num_kv_shared_layers cannot exceed the model layer count")
+31 -2
View File
@@ -109,7 +109,7 @@ def test_model_load_policy_precedence_is_explicit(overrides, expected):
def test_model_load_policy_rejects_unsupported_quantization_before_branching():
with pytest.raises(ValueError, match="Unknown quantization '3bit'"):
with pytest.raises(ValueError) as error:
resolve_model_load_policy(
device="auto",
resolved_device="cuda",
@@ -119,6 +119,7 @@ def test_model_load_policy_rejects_unsupported_quantization_before_branching():
device_map_auto_supported=True,
bitsandbytes_supported=True,
)
assert str(error.value) == "Unknown quantization '3bit'. Choose None, '4bit', or '8bit'"
@pytest.mark.parametrize("quantization", ["4bit", "8bit"])
@@ -166,6 +167,17 @@ def test_output_only_projection_is_independent_of_shared_kv_layout():
) == _OUTPUT_NAMES
def test_nonshared_projection_does_not_require_shared_storage_ownership_metadata():
assert attention_projection_names(
projection_target="all",
layer_index=-1,
num_layers=0,
num_kv_shared_layers=0,
output_names=_OUTPUT_NAMES,
input_names=_INPUT_NAMES,
) == _OUTPUT_NAMES + _INPUT_NAMES
@pytest.mark.parametrize(
("layer_index", "expected"),
[
@@ -186,6 +198,17 @@ def test_shared_kv_owner_projects_storage_once_and_borrowers_skip_it(layer_index
) == expected
def test_single_layer_can_own_kv_storage_shared_by_the_whole_model():
assert attention_projection_names(
projection_target="all",
layer_index=0,
num_layers=1,
num_kv_shared_layers=1,
output_names=_OUTPUT_NAMES,
input_names=_INPUT_NAMES,
) == _OUTPUT_NAMES + _INPUT_NAMES
@pytest.mark.parametrize(
("layer_index", "num_layers", "shared_layers", "message"),
[
@@ -201,7 +224,7 @@ def test_shared_kv_layout_rejects_impossible_ownership(
shared_layers,
message,
):
with pytest.raises(ValueError, match=message):
with pytest.raises(ValueError) as error:
attention_projection_names(
projection_target="all",
layer_index=layer_index,
@@ -210,6 +233,12 @@ def test_shared_kv_layout_rejects_impossible_ownership(
output_names=_OUTPUT_NAMES,
input_names=_INPUT_NAMES,
)
expected = (
"num_kv_shared_layers cannot exceed the model layer count"
if message == "cannot exceed"
else "shared-KV projection requires a valid layer index and layer count"
)
assert str(error.value) == expected
@pytest.mark.parametrize(