Skip to content

Commit

Permalink
Fix PA build
Browse files Browse the repository at this point in the history
  • Loading branch information
vshampor committed Dec 3, 2024
1 parent b0d3b16 commit 2b54673
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 33 deletions.
2 changes: 2 additions & 0 deletions src/plugins/intel_cpu/tests/unit/vectorized/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ ov_add_test_target(
unit_test_utils
ov_snippets_models
snippets_test_utils
${MLAS_LIBRARY}
${SHL_LIBRARY}
ADD_CPPLINT
LABELS
OV UNIT CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_models_list_type(file_name: str, cls: Union[Type[OVModelForCausalLM], Ty
models.append((model_name, model_link, None, None, cls))
elif len(line_items) == 4:
model_name, model_link, mark, reason = line_items
models.append((model_name, model_link, mark, reason))
models.append((model_name, model_link, mark, reason, cls))
elif len(line_items) > 4:
model_name, model_link, mark, reason, *other = line_items
if not mark:
Expand Down
39 changes: 16 additions & 23 deletions tests/model_hub_tests/transformation_tests/sdpa2pa_ref_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

nodes_to_compare = ("ScaledDotProductAttention", "PagedAttentionExtension", "Parameter", "ReadValue", "Assign")


ref_diff_map = {
"hf-internal-testing/tiny-random-LlamaForCausalLM" : {
"Assign" : -4,
Expand Down Expand Up @@ -299,36 +300,36 @@
"ScaledDotProductAttention" : -6,
},
"katuni4ka/tiny-random-llava-next" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
"Parameter" : 7,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
"Assign" : -4,
},
"katuni4ka/tiny-random-minicpmv-2_6" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
"Parameter" : 7,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
"Assign" : -4,
},
"katuni4ka/tiny-random-llava" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
"Parameter" : 7,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
"PagedAttentionExtension" : 2,
},

# "katuni4ka/tiny-random-nanollava" : {
# "Assign" : -4,
# "PagedAttentionExtension" : 2,
# "Parameter" : 7,
# "ReadValue" : -4,
# "ScaledDotProductAttention" : -2,
# "PagedAttentionExtension" : 2,
# },
}


ref_diff_map_cache_eviction = {
"hf-internal-testing/tiny-random-LlamaForCausalLM" : {
"Assign" : -4,
Expand Down Expand Up @@ -554,13 +555,6 @@
"ReadValue" : -8,
"ScaledDotProductAttention" : -4,
},
"katuni4ka/tiny-random-minicpm" : {
"Assign" : -8,
"PagedAttentionExtension" : 4,
"Parameter" : 14,
"ReadValue" : -8,
"ScaledDotProductAttention" : -4,
},
"katuni4ka/tiny-random-falcon-40b" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
Expand Down Expand Up @@ -632,32 +626,31 @@
"ScaledDotProductAttention" : -6,
},
"katuni4ka/tiny-random-llava-next" : {
"Parameter" : 8,
"Assign" : -4,
"ReadValue" : -4,
"PagedAttentionExtension" : 2,
"Parameter" : 12,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-minicpmv-2_6" : {
"Parameter" : 8,
"Assign" : -4,
"ReadValue" : -4,
"PagedAttentionExtension" : 2,
"Parameter" : 12,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-llava" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
"Parameter" : 12,
"ReadValue" : -4,
"Parameter" : 8,
"ScaledDotProductAttention" : -2,
"PagedAttentionExtension" : 2,
"Assign" : -4,
},

# "katuni4ka/tiny-random-nanollava" : {
# "Assign" : -4,
# "PagedAttentionExtension" : 2,
# "Parameter" : 12,
# "ReadValue" : -4,
# "Parameter" : 8,
# "ScaledDotProductAttention" : -2,
# "PagedAttentionExtension" : 2,
# "Assign" : -4,
# },
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def compare_diffs(ov_model: ov.Model,
for op in set(after_map.keys()) | set(before_map.keys()):
resulting_map[op] = after_map.get(op, 0) - before_map.get(op, 0)

use_cache_eviction = use_block_indices_inputs and use_score_outputs
use_cache_eviction = use_block_indices_inputs and use_score_outputs and allow_cache_rotation
reference_map = ref_diff_map_cache_eviction[model_id] if use_cache_eviction else ref_diff_map[model_id]

assert reference_map == resulting_map
Expand All @@ -58,14 +58,14 @@ def compare_diffs(ov_model: ov.Model,

# Test for block_indices inputs and scores outputs to appear in the model
if (use_block_indices_inputs):
interesting_input_patterns["block_indices"] = r'block_indices\.[0-9]+'
interesting_input_patterns["block_indices"] = r'^block_indices\.[0-9]+'

if (use_score_outputs):
interesting_output_patterns["scores"] = r'scores\.[0-9]+'
interesting_output_patterns["scores"] = r'^scores\.[0-9]+'

if (allow_cache_rotation):
interesting_input_patterns["rotation_coefficients"] = r'rotation_coefficients\.[0-9]+';
interesting_input_patterns["rotated_block_indices"] = r'rotated_block_indices\.[0-9]+';
interesting_input_patterns["rotation_coefficients"] = r'^rotation_coefficients\.[0-9]+';
interesting_input_patterns["rotated_block_indices"] = r'^rotated_block_indices\.[0-9]+';

input_counters = {k: 0 for k in interesting_input_patterns}
output_counters = {k: 0 for k in interesting_output_patterns}
Expand Down Expand Up @@ -95,11 +95,12 @@ def run_pa(tmp_path,
model_link,
cls: Union[Type[OVModelForCausalLM], Type[OVModelForVisualCausalLM]],
use_block_indices_inputs,
use_score_outputs):
use_score_outputs,
allow_cache_rotation):
model = cls.from_pretrained(model_id, export=True, trust_remote_code=True)
ov_model = model.model if cls is OVModelForCausalLM else model.lm_model

compare_diffs(ov_model, model_id, use_block_indices_inputs, use_score_outputs)
compare_diffs(ov_model, model_id, use_block_indices_inputs, use_score_outputs, allow_cache_rotation)

@pytest.mark.precommit
@pytest.mark.parametrize("model_name, model_link, mark, reason", utils.get_models_list(os.path.join(os.path.dirname(__file__), "models", "hf-tiny-random-models-precommit")))
Expand All @@ -110,7 +111,7 @@ def test_pa_precommit(tmp_path, model_name, model_link, mark, reason, ie_device)
pytest.skip(reason)
elif mark == 'xfail':
pytest.xfail(reason)
run_pa(tmp_path, model_name, model_link, OVModelForCausalLM False, False, False)
run_pa(tmp_path, model_name, model_link, OVModelForCausalLM, False, False, False)

@pytest.mark.precommit
@pytest.mark.parametrize("model_name, model_link, mark, reason", utils.get_models_list(os.path.join(os.path.dirname(__file__), "models", "hf-tiny-random-models-precommit")))
Expand All @@ -121,7 +122,7 @@ def test_pa_precommit_use_cache_eviction(tmp_path, model_name, model_link, mark,
pytest.skip(reason)
elif mark == 'xfail':
pytest.xfail(reason)
run_pa(tmp_path, model_name, model_link, OVModelForCausalLM, True, True)
run_pa(tmp_path, model_name, model_link, OVModelForCausalLM, True, True, True)

@pytest.mark.precommit
@pytest.mark.parametrize("model_name, model_link, mark, reason", utils.get_models_list(os.path.join(os.path.dirname(__file__), "models", "hf-tiny-random-vl-models-precommit")))
Expand Down

0 comments on commit 2b54673

Please sign in to comment.