From b2ed787a81a0814089a9d31219eef6da615af1e5 Mon Sep 17 00:00:00 2001 From: Arthur Zucker Date: Mon, 1 Apr 2024 11:45:12 +0200 Subject: [PATCH 1/4] fix copies --- .../qwen2_moe/test_modeling_qwen2_moe.py | 2 +- utils/check_copies.py | 25 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/models/qwen2_moe/test_modeling_qwen2_moe.py b/tests/models/qwen2_moe/test_modeling_qwen2_moe.py index b6f8df27efaa9e..e322e5f8490092 100644 --- a/tests/models/qwen2_moe/test_modeling_qwen2_moe.py +++ b/tests/models/qwen2_moe/test_modeling_qwen2_moe.py @@ -504,7 +504,7 @@ def test_flash_attn_2_generate_use_cache(self): @require_torch_gpu @pytest.mark.flash_attn_test @slow - def test_flash_attn_2_inference_padding_right(self): + def test_flash_attn_2_inference_equivalence_right_padding(self): self.skipTest("Qwen2Moe flash attention does not support right padding") # Ignore copy diff --git a/utils/check_copies.py b/utils/check_copies.py index 3756089575801c..3e79376b7e14b2 100644 --- a/utils/check_copies.py +++ b/utils/check_copies.py @@ -313,10 +313,10 @@ def split_code_into_blocks( target_block_name = re.search( rf"^{' ' * (indent - 4)}((class|def)\s+\S+)(\(|\:)", lines[start_index] ).groups()[0] - except ValueError: + except Exception: raise ValueError( - f"Tried to split a class or function. It did not work. Error comes from line {start_index}: ```\n" - + "".join(lines[start_index:end_index]) + f"Tried to split a class or function. It did not work. Error comes from line {start_index}: \n```\n" + + "".join(lines[start_index - 10 : end_index + 10]) + "```\n" ) @@ -602,8 +602,23 @@ def check_codes_match(observed_code: str, theoretical_code: str) -> Optional[int _re_func_match = re.compile(r"def\s+([^\(]+)\(") for re_pattern in [_re_class_match, _re_func_match]: if re_pattern.match(observed_code_header) is not None: - observed_obj_name = re_pattern.search(observed_code_header).groups()[0] - theoretical_name = re_pattern.search(theoretical_code_header).groups()[0] + try: + observed_obj_name = re_pattern.search(observed_code_header).groups()[0] + except Exception: + raise ValueError( + "Tried to split a class or function. It did not work. Error comes from: \n```\n" + + observed_code_header + + "\n```\n" + ) + + try: + theoretical_name = re_pattern.search(theoretical_code_header).groups()[0] + except Exception: + raise ValueError( + "Tried to split a class or function. It did not work. Error comes from: \n```\n" + + observed_code_header + + "\n```\n" + ) theoretical_code_header = theoretical_code_header.replace(theoretical_name, observed_obj_name) # Find the first diff. Line 0 is special since we need to compare with the function/class names ignored. From d9cb2ce7f92df9ad21abb8ea9cba82eba0eabce3 Mon Sep 17 00:00:00 2001 From: Arthur Zucker Date: Mon, 1 Apr 2024 11:47:40 +0200 Subject: [PATCH 2/4] nit --- utils/check_copies.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/check_copies.py b/utils/check_copies.py index 3e79376b7e14b2..1b03816afd6b76 100644 --- a/utils/check_copies.py +++ b/utils/check_copies.py @@ -314,9 +314,11 @@ def split_code_into_blocks( rf"^{' ' * (indent - 4)}((class|def)\s+\S+)(\(|\:)", lines[start_index] ).groups()[0] except Exception: + start_context = min(start_index-10, 0) + end_context = min(end_index+10, len(lines)) raise ValueError( f"Tried to split a class or function. It did not work. Error comes from line {start_index}: \n```\n" - + "".join(lines[start_index - 10 : end_index + 10]) + + "".join(lines[start_context:end_context]) + "```\n" ) From d1b9a634cde22faf275cc351a966cb8b254e8795 Mon Sep 17 00:00:00 2001 From: Arthur Zucker Date: Mon, 1 Apr 2024 11:52:14 +0200 Subject: [PATCH 3/4] style --- utils/check_copies.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/check_copies.py b/utils/check_copies.py index 1b03816afd6b76..8282965bdcd43a 100644 --- a/utils/check_copies.py +++ b/utils/check_copies.py @@ -314,8 +314,8 @@ def split_code_into_blocks( rf"^{' ' * (indent - 4)}((class|def)\s+\S+)(\(|\:)", lines[start_index] ).groups()[0] except Exception: - start_context = min(start_index-10, 0) - end_context = min(end_index+10, len(lines)) + start_context = min(start_index - 10, 0) + end_context = min(end_index + 10, len(lines)) raise ValueError( f"Tried to split a class or function. It did not work. Error comes from line {start_index}: \n```\n" + "".join(lines[start_context:end_context]) From dbce891e27ece4afbf17ac6fc6f77f256cfbf5be Mon Sep 17 00:00:00 2001 From: Arthur <48595927+ArthurZucker@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:04:42 +0200 Subject: [PATCH 4/4] Update utils/check_copies.py --- utils/check_copies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/check_copies.py b/utils/check_copies.py index 8282965bdcd43a..60a2fac4c8f57d 100644 --- a/utils/check_copies.py +++ b/utils/check_copies.py @@ -618,7 +618,7 @@ def check_codes_match(observed_code: str, theoretical_code: str) -> Optional[int except Exception: raise ValueError( "Tried to split a class or function. It did not work. Error comes from: \n```\n" - + observed_code_header + + theoretical_code_header + "\n```\n" ) theoretical_code_header = theoretical_code_header.replace(theoretical_name, observed_obj_name)