From 626cec2dfc4a40f3d4e21505294d195f59c4ae68 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Mon, 27 Nov 2023 14:57:38 +0000 Subject: [PATCH 01/27] update setup and deps table --- setup.py | 2 ++ src/diffusers/dependency_versions_table.py | 1 + 2 files changed, 3 insertions(+) diff --git a/setup.py b/setup.py index 1c645d769a5c..658f15167e4f 100644 --- a/setup.py +++ b/setup.py @@ -121,6 +121,7 @@ "ruff>=0.1.5,<=0.2", "safetensors>=0.3.1", "sentencepiece>=0.1.91,!=0.1.92", + "GitPython", "scipy", "onnx", "regex!=2019.12.17", @@ -206,6 +207,7 @@ def run(self): extras["training"] = deps_list("accelerate", "datasets", "protobuf", "tensorboard", "Jinja2") extras["test"] = deps_list( "compel", + "GitPython", "datasets", "Jinja2", "invisible-watermark", diff --git a/src/diffusers/dependency_versions_table.py b/src/diffusers/dependency_versions_table.py index 7ec2e2cf6d5c..5b8dc840ad3d 100644 --- a/src/diffusers/dependency_versions_table.py +++ b/src/diffusers/dependency_versions_table.py @@ -33,6 +33,7 @@ "ruff": "ruff>=0.1.5,<=0.2", "safetensors": "safetensors>=0.3.1", "sentencepiece": "sentencepiece>=0.1.91,!=0.1.92", + "GitPython": "GitPython", "scipy": "scipy", "onnx": "onnx", "regex": "regex!=2019.12.17", From e49743524d6b3a3886727834142380ed357f5f3f Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Mon, 27 Nov 2023 17:15:13 +0000 Subject: [PATCH 02/27] update --- .github/workflows/pr_test_fetcher.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr_test_fetcher.yml b/.github/workflows/pr_test_fetcher.yml index 7eb208505e75..53d91f1eb23d 100644 --- a/.github/workflows/pr_test_fetcher.yml +++ b/.github/workflows/pr_test_fetcher.yml @@ -39,7 +39,7 @@ jobs: - name: Install dependencies run: | apt-get update && apt-get install libsndfile1-dev libgl1 -y - python -m pip install -e . + python -m pip install -e .[quality,test] - name: Environment run: | python utils/print_env.py From 420a66b112a97efbbae5bd8aa582535d66ba4ee6 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Mon, 27 Nov 2023 17:23:16 +0000 Subject: [PATCH 03/27] update --- .github/workflows/pr_test_fetcher.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr_test_fetcher.yml b/.github/workflows/pr_test_fetcher.yml index 53d91f1eb23d..b4ea4d44de10 100644 --- a/.github/workflows/pr_test_fetcher.yml +++ b/.github/workflows/pr_test_fetcher.yml @@ -43,6 +43,7 @@ jobs: - name: Environment run: | python utils/print_env.py + echo $(git --version) - name: Fetch Tests run: | python utils/tests_fetcher.py | tee test_preparation.txt From 3ec55b9f8ca8f160130946b99559d0882c20e771 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Mon, 27 Nov 2023 18:12:08 +0000 Subject: [PATCH 04/27] update --- setup.py | 2 +- src/diffusers/dependency_versions_table.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 658f15167e4f..c2382deb2381 100644 --- a/setup.py +++ b/setup.py @@ -121,7 +121,7 @@ "ruff>=0.1.5,<=0.2", "safetensors>=0.3.1", "sentencepiece>=0.1.91,!=0.1.92", - "GitPython", + "GitPython<3.1.19", "scipy", "onnx", "regex!=2019.12.17", diff --git a/src/diffusers/dependency_versions_table.py b/src/diffusers/dependency_versions_table.py index 5b8dc840ad3d..ab9212458895 100644 --- a/src/diffusers/dependency_versions_table.py +++ b/src/diffusers/dependency_versions_table.py @@ -33,7 +33,7 @@ "ruff": "ruff>=0.1.5,<=0.2", "safetensors": "safetensors>=0.3.1", "sentencepiece": "sentencepiece>=0.1.91,!=0.1.92", - "GitPython": "GitPython", + "GitPython": "GitPython<3.1.19", "scipy": "scipy", "onnx": "onnx", "regex": "regex!=2019.12.17", From a0db70e3e6f5eb0821206bfa6e9872c4a1d505c7 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Wed, 29 Nov 2023 09:36:56 +0000 Subject: [PATCH 05/27] up --- utils/tests_fetcher.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index 365310f415a2..27d48d25552d 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -83,6 +83,9 @@ # Ignore lora since they are always tested MODULES_TO_IGNORE = ["fixtures", "lora"] +repo = Repo(PATH_TO_REPO) +print("Active Branch: ", repo.active_branch) +print("Refs: ", repo.refs) @contextmanager def checkout_commit(repo: Repo, commit_id: str): From 31c0ef737a270d322f3bc8a8013ff1806e4c654f Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Wed, 29 Nov 2023 09:50:38 +0000 Subject: [PATCH 06/27] up --- utils/tests_fetcher.py | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index 27d48d25552d..b14a421d3432 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -84,7 +84,6 @@ MODULES_TO_IGNORE = ["fixtures", "lora"] repo = Repo(PATH_TO_REPO) -print("Active Branch: ", repo.active_branch) print("Refs: ", repo.refs) @contextmanager From a13adc964d5c6b3e7412da905b35b844ee93630a Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Wed, 29 Nov 2023 14:12:06 +0000 Subject: [PATCH 07/27] update --- .github/workflows/pr_test_fetcher.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr_test_fetcher.yml b/.github/workflows/pr_test_fetcher.yml index b4ea4d44de10..622cd489e843 100644 --- a/.github/workflows/pr_test_fetcher.yml +++ b/.github/workflows/pr_test_fetcher.yml @@ -35,7 +35,7 @@ jobs: - name: Checkout diffusers uses: actions/checkout@v3 with: - fetch-depth: 2 + fetch-depth: 0 - name: Install dependencies run: | apt-get update && apt-get install libsndfile1-dev libgl1 -y From 00b1936b82be2ecc78f852c3e0917b078154e5e1 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Wed, 29 Nov 2023 16:34:19 +0000 Subject: [PATCH 08/27] up --- utils/tests_fetcher.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index b14a421d3432..55469a48306f 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -84,7 +84,8 @@ MODULES_TO_IGNORE = ["fixtures", "lora"] repo = Repo(PATH_TO_REPO) -print("Refs: ", repo.refs) +print(type(repo.refs)) +print("Main is at: ", repo.refs.main.commit) @contextmanager def checkout_commit(repo: Repo, commit_id: str): @@ -978,6 +979,7 @@ def infer_tests_to_run( def filter_tests(output_file: str, filters: List[str]): + """ Reads the content of the output file and filters out all the tests in a list of given folders. @@ -985,6 +987,9 @@ def filter_tests(output_file: str, filters: List[str]): output_file (`str` or `os.PathLike`): The path to the output file of the tests fetcher. filters (`List[str]`): A list of folders to filter. """ + print("Filtering Tests") + print("----------------") + if not os.path.isfile(output_file): print("No test file found.") return From 527216fe1afc5a1676063d5d0e41cecb59e1bbfc Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 11:11:19 +0000 Subject: [PATCH 09/27] update --- utils/tests_fetcher.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index 55469a48306f..d7c53315eacc 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -85,6 +85,7 @@ repo = Repo(PATH_TO_REPO) print(type(repo.refs)) +print(repo.refs) print("Main is at: ", repo.refs.main.commit) @contextmanager From ca6b0616a6609c1f0af6a9685da9da526815cb95 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 11:54:02 +0000 Subject: [PATCH 10/27] update --- utils/tests_fetcher.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index d7c53315eacc..21d5e331761b 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -86,7 +86,7 @@ repo = Repo(PATH_TO_REPO) print(type(repo.refs)) print(repo.refs) -print("Main is at: ", repo.refs.main.commit) +print("main", repo.remotes.origin.refs.main.commit) @contextmanager def checkout_commit(repo: Repo, commit_id: str): @@ -293,10 +293,11 @@ def get_modified_python_files(diff_with_last_commit: bool = False) -> List[str]: repo = Repo(PATH_TO_REPO) if not diff_with_last_commit: - print(f"main is at {repo.refs.main.commit}") + main_branch = repo.remotes.origin.refs.main + print(f"main is at {main_branch.commit}") print(f"Current head is at {repo.head.commit}") - branching_commits = repo.merge_base(repo.refs.main, repo.head) + branching_commits = repo.merge_base(main_branch, repo.head) for commit in branching_commits: print(f"Branching commit: {commit}") return get_diff(repo, repo.head.commit, branching_commits) From 7aa39e7310c624360e84d504cb3e0a8f46c85093 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 12:08:26 +0000 Subject: [PATCH 11/27] update --- .github/workflows/pr_test_fetcher.yml | 2 +- utils/tests_fetcher.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr_test_fetcher.yml b/.github/workflows/pr_test_fetcher.yml index 622cd489e843..b4ea4d44de10 100644 --- a/.github/workflows/pr_test_fetcher.yml +++ b/.github/workflows/pr_test_fetcher.yml @@ -35,7 +35,7 @@ jobs: - name: Checkout diffusers uses: actions/checkout@v3 with: - fetch-depth: 0 + fetch-depth: 2 - name: Install dependencies run: | apt-get update && apt-get install libsndfile1-dev libgl1 -y diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index 21d5e331761b..5ef14d0c11e7 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -86,6 +86,7 @@ repo = Repo(PATH_TO_REPO) print(type(repo.refs)) print(repo.refs) +print(repo.remotes.origin.refs) print("main", repo.remotes.origin.refs.main.commit) @contextmanager From e9a76ac91b5b1fe1e2d3bda7b8d187c91581645e Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 12:38:12 +0000 Subject: [PATCH 12/27] update --- .github/workflows/pr_test_fetcher.yml | 2 +- utils/tests_fetcher.py | 35 +++++++++++++-------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.github/workflows/pr_test_fetcher.yml b/.github/workflows/pr_test_fetcher.yml index b4ea4d44de10..622cd489e843 100644 --- a/.github/workflows/pr_test_fetcher.yml +++ b/.github/workflows/pr_test_fetcher.yml @@ -35,7 +35,7 @@ jobs: - name: Checkout diffusers uses: actions/checkout@v3 with: - fetch-depth: 2 + fetch-depth: 0 - name: Install dependencies run: | apt-get update && apt-get install libsndfile1-dev libgl1 -y diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index 5ef14d0c11e7..74d3adb147b7 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -83,12 +83,6 @@ # Ignore lora since they are always tested MODULES_TO_IGNORE = ["fixtures", "lora"] -repo = Repo(PATH_TO_REPO) -print(type(repo.refs)) -print(repo.refs) -print(repo.remotes.origin.refs) -print("main", repo.remotes.origin.refs.main.commit) - @contextmanager def checkout_commit(repo: Repo, commit_id: str): """ @@ -294,11 +288,13 @@ def get_modified_python_files(diff_with_last_commit: bool = False) -> List[str]: repo = Repo(PATH_TO_REPO) if not diff_with_last_commit: - main_branch = repo.remotes.origin.refs.main - print(f"main is at {main_branch.commit}") + # Need to fetch refs for main using remotes when running with github actions. + upstream_main = repo.remotes.origin.refs.main + + print(f"main is at {upstream_main.commit}") print(f"Current head is at {repo.head.commit}") - branching_commits = repo.merge_base(main_branch, repo.head) + branching_commits = repo.merge_base(upstream_main, repo.head) for commit in branching_commits: print(f"Branching commit: {commit}") return get_diff(repo, repo.head.commit, branching_commits) @@ -421,10 +417,11 @@ def get_doctest_files(diff_with_last_commit: bool = False) -> List[str]: test_files_to_run = [] # noqa if not diff_with_last_commit: - print(f"main is at {repo.refs.main.commit}") + upstream_main = repo.remotes.origin.refs.main + print(f"main is at {upstream_main.commit}") print(f"Current head is at {repo.head.commit}") - branching_commits = repo.merge_base(repo.refs.main, repo.head) + branching_commits = repo.merge_base(upstream_main, repo.head) for commit in branching_commits: print(f"Branching commit: {commit}") test_files_to_run = get_diff_for_doctesting(repo, repo.head.commit, branching_commits) @@ -438,7 +435,7 @@ def get_doctest_files(diff_with_last_commit: bool = False) -> List[str]: all_test_files_to_run = get_all_doctest_files() # Add to the test files to run any removed entry from "utils/not_doctested.txt". - new_test_files = get_new_doctest_files(repo, repo.head.commit, repo.refs.main.commit) + new_test_files = get_new_doctest_files(repo, repo.head.commit, upstream_main.commit) test_files_to_run = list(set(test_files_to_run + new_test_files)) # Do not run slow doctest tests on CircleCI @@ -814,18 +811,20 @@ def is_test(fname): return test_map # Now we deal with the filtering if `filter_models` is True. - num_model_tests = len(list(PATH_TO_TESTS.glob("models/*"))) + num_pipelines_tests = len(list(PATH_TO_TESTS.glob("pipelines/*"))) - def has_many_models(tests): + def has_many_pipelines(tests): # We filter to core models when a given file impacts more than half the model tests. - model_tests = {Path(t).parts[2] for t in tests if t.startswith("tests/models/")} - return len(model_tests) > num_model_tests // 2 + pipeline_tests = {Path(t).parts[2] for t in tests if t.startswith("tests/pipelines/")} + return len(pipeline_tests) > num_pipelines_tests // 2 def filter_tests(tests): - return [t for t in tests if not t.startswith("tests/models/") or Path(t).parts[2] in IMPORTANT_PIPELINES] + return [t for t in tests if not t.startswith("tests/pipelines/") or Path(t).parts[2] in IMPORTANT_PIPELINES] - return {module: (filter_tests(tests) if has_many_models(tests) else tests) for module, tests in test_map.items()} + tests_to_run = {module: (filter_tests(tests) if has_many_pipelines(tests) else tests) for module, tests in test_map.items()} + import ipdb; ipdb.set_trace() + return tests_to_run def check_imports_all_exist(): """ From 20fecbf1a8b5efff231afbe6dc664d5f5dda6bed Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 12:39:47 +0000 Subject: [PATCH 13/27] update --- utils/tests_fetcher.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index 74d3adb147b7..869f478a73b5 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -989,9 +989,6 @@ def filter_tests(output_file: str, filters: List[str]): output_file (`str` or `os.PathLike`): The path to the output file of the tests fetcher. filters (`List[str]`): A list of folders to filter. """ - print("Filtering Tests") - print("----------------") - if not os.path.isfile(output_file): print("No test file found.") return From 007f06a715dc70185446604712bdf8f3eeb03005 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 12:43:16 +0000 Subject: [PATCH 14/27] update --- utils/tests_fetcher.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index 869f478a73b5..23cb0d9e460e 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -806,6 +806,9 @@ def is_test(fname): # Build the test map test_map = {module: [f for f in deps if is_test(f)] for module, deps in reverse_map.items()} + tests_to_run = {module: (filter_tests(tests) if has_many_pipelines(tests) else tests) for module, tests in test_map.items()} + + import ipdb; ipdb.set_trace() if not filter_models: return test_map @@ -822,7 +825,6 @@ def filter_tests(tests): return [t for t in tests if not t.startswith("tests/pipelines/") or Path(t).parts[2] in IMPORTANT_PIPELINES] tests_to_run = {module: (filter_tests(tests) if has_many_pipelines(tests) else tests) for module, tests in test_map.items()} - import ipdb; ipdb.set_trace() return tests_to_run From 61ef8b7e790b5e58091a087471ac4f7dba197e6f Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 12:47:10 +0000 Subject: [PATCH 15/27] update --- utils/tests_fetcher.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index 23cb0d9e460e..da6f94fec76e 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -793,6 +793,8 @@ def create_module_to_test_map( Returns: `Dict[str, List[str]]`: A dictionary that maps each file to the tests to execute if that file was modified. """ + import ipdb; ipdb.set_trace() + if reverse_map is None: reverse_map = create_reverse_dependency_map() @@ -808,8 +810,6 @@ def is_test(fname): test_map = {module: [f for f in deps if is_test(f)] for module, deps in reverse_map.items()} tests_to_run = {module: (filter_tests(tests) if has_many_pipelines(tests) else tests) for module, tests in test_map.items()} - import ipdb; ipdb.set_trace() - if not filter_models: return test_map @@ -933,6 +933,8 @@ def infer_tests_to_run( impacted_files = sorted(set(impacted_files)) print(f"\n### IMPACTED FILES ###\n{_print_list(impacted_files)}") + import ipdb; ipdb.set_trace() + # Grab the corresponding test files: if any(x in modified_files for x in ["setup.py"]): test_files_to_run = ["tests", "examples"] From 687d540fd515214a344537746ba626d837211fe6 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 13:31:34 +0000 Subject: [PATCH 16/27] update --- utils/tests_fetcher.py | 48 +++++------------------------------------- 1 file changed, 5 insertions(+), 43 deletions(-) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index da6f94fec76e..65de43a3fd4d 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -66,19 +66,6 @@ PATH_TO_DIFFUSERS = PATH_TO_REPO / "src/diffusers" PATH_TO_TESTS = PATH_TO_REPO / "tests" -# List here the pipelines to always test. -IMPORTANT_PIPELINES = [ - "controlnet", - "stable_diffusion", - "stable_diffusion_2", - "stable_diffusion_xl", - "deepfloyd_if", - "kandinsky", - "kandinsky2_2", - "text_to_video_synthesis", - "wuerstchen", -] - # Ignore fixtures in tests folder # Ignore lora since they are always tested MODULES_TO_IGNORE = ["fixtures", "lora"] @@ -778,7 +765,7 @@ def create_reverse_dependency_map() -> Dict[str, List[str]]: def create_module_to_test_map( - reverse_map: Dict[str, List[str]] = None, filter_models: bool = False + reverse_map: Dict[str, List[str]] = None ) -> Dict[str, List[str]]: """ Extract the tests from the reverse_dependency_map and potentially filters the model tests. @@ -787,14 +774,12 @@ def create_module_to_test_map( reverse_map (`Dict[str, List[str]]`, *optional*): The reverse dependency map as created by `create_reverse_dependency_map`. Will default to the result of that function if not provided. - filter_models (`bool`, *optional*, defaults to `False`): - Whether or not to filter model tests to only include core models if a file impacts a lot of models. + filter_pipelines (`bool`, *optional*, defaults to `False`): + Whether or not to filter pipeline tests to only include core pipelines if a file impacts a lot of models. Returns: `Dict[str, List[str]]`: A dictionary that maps each file to the tests to execute if that file was modified. """ - import ipdb; ipdb.set_trace() - if reverse_map is None: reverse_map = create_reverse_dependency_map() @@ -808,25 +793,8 @@ def is_test(fname): # Build the test map test_map = {module: [f for f in deps if is_test(f)] for module, deps in reverse_map.items()} - tests_to_run = {module: (filter_tests(tests) if has_many_pipelines(tests) else tests) for module, tests in test_map.items()} - - if not filter_models: - return test_map - - # Now we deal with the filtering if `filter_models` is True. - num_pipelines_tests = len(list(PATH_TO_TESTS.glob("pipelines/*"))) - def has_many_pipelines(tests): - # We filter to core models when a given file impacts more than half the model tests. - pipeline_tests = {Path(t).parts[2] for t in tests if t.startswith("tests/pipelines/")} - return len(pipeline_tests) > num_pipelines_tests // 2 - - def filter_tests(tests): - return [t for t in tests if not t.startswith("tests/pipelines/") or Path(t).parts[2] in IMPORTANT_PIPELINES] - - tests_to_run = {module: (filter_tests(tests) if has_many_pipelines(tests) else tests) for module, tests in test_map.items()} - - return tests_to_run + return test_map def check_imports_all_exist(): """ @@ -895,7 +863,6 @@ def create_json_map(test_files_to_run: List[str], json_output_file: str): def infer_tests_to_run( output_file: str, diff_with_last_commit: bool = False, - filter_models: bool = True, json_output_file: Optional[str] = None, ): """ @@ -933,8 +900,6 @@ def infer_tests_to_run( impacted_files = sorted(set(impacted_files)) print(f"\n### IMPACTED FILES ###\n{_print_list(impacted_files)}") - import ipdb; ipdb.set_trace() - # Grab the corresponding test files: if any(x in modified_files for x in ["setup.py"]): test_files_to_run = ["tests", "examples"] @@ -948,7 +913,7 @@ def infer_tests_to_run( f for f in modified_files if f.startswith("tests") and f.split(os.path.sep)[-1].startswith("test") ] # Then we grab the corresponding test files. - test_map = create_module_to_test_map(reverse_map=reverse_map, filter_models=filter_models) + test_map = create_module_to_test_map(reverse_map=reverse_map) for f in modified_files: if f in test_map: test_files_to_run.extend(test_map[f]) @@ -1074,8 +1039,6 @@ def parse_commit_message(commit_message: str) -> Dict[str, bool]: args = parser.parse_args() if args.print_dependencies_of is not None: print_tree_deps_of(args.print_dependencies_of) - elif args.filter_tests: - filter_tests(args.output_file, ["pipelines", "repo_utils"]) else: repo = Repo(PATH_TO_REPO) commit_message = repo.head.commit.message @@ -1099,7 +1062,6 @@ def parse_commit_message(commit_message: str) -> Dict[str, bool]: args.output_file, diff_with_last_commit=diff_with_last_commit, json_output_file=args.json_output_file, - filter_models=not commit_flags["no_filter"], ) filter_tests(args.output_file, ["repo_utils"]) except Exception as e: From 1845ca173c04bc0b29de4844738ee545b199de5d Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 14:14:47 +0000 Subject: [PATCH 17/27] update --- utils/tests_fetcher.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index 65de43a3fd4d..bb6cc22f401a 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -70,6 +70,19 @@ # Ignore lora since they are always tested MODULES_TO_IGNORE = ["fixtures", "lora"] +IMPORTANT_PIPELINES = [ + "controlnet", + "stable_diffusion", + "stable_diffusion_2", + "stable_diffusion_xl", + "stable_video_diffusion", + "deepfloyd_if", + "kandinsky", + "kandinsky2_2", + "text_to_video_synthesis", + "wuerstchen", +] + @contextmanager def checkout_commit(repo: Repo, commit_id: str): """ @@ -794,6 +807,22 @@ def is_test(fname): # Build the test map test_map = {module: [f for f in deps if is_test(f)] for module, deps in reverse_map.items()} + # Always test core pipelines + if "pipelines" not in test_map: + test_map["pipelines"] = [PATH_TO_TESTS / f"pipelines/{pipe}" for pipe in IMPORTANT_PIPELINES] + + else: + pipeline_tests = [] + # first remove individual test files from core pipeline modules that might have been added + for pipe in test_map["pipelines"]: + if Path(pipe).parts(2) in IMPORTANT_PIPELINES: + continue + pipeline_tests.append(pipe) + + # add entire core pipline modules instead + pipeline_tests.extend([PATH_TO_TESTS / f"pipelines/{pipe}" for pipe in IMPORTANT_PIPELINES]) + test_map["pipelines"] = pipeline_tests + return test_map def check_imports_all_exist(): From c23f34294ed997871522175f9c06af0a8e88a905 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 14:18:47 +0000 Subject: [PATCH 18/27] update --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index c2382deb2381..a22dd9e0c9cc 100644 --- a/setup.py +++ b/setup.py @@ -121,7 +121,6 @@ "ruff>=0.1.5,<=0.2", "safetensors>=0.3.1", "sentencepiece>=0.1.91,!=0.1.92", - "GitPython<3.1.19", "scipy", "onnx", "regex!=2019.12.17", From daa25b94a3e8f510dc22f63ca0a2444e3484579c Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 14:19:33 +0000 Subject: [PATCH 19/27] update --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index a22dd9e0c9cc..c2382deb2381 100644 --- a/setup.py +++ b/setup.py @@ -121,6 +121,7 @@ "ruff>=0.1.5,<=0.2", "safetensors>=0.3.1", "sentencepiece>=0.1.91,!=0.1.92", + "GitPython<3.1.19", "scipy", "onnx", "regex!=2019.12.17", From 20a68c986386999215bafacf02d3652a74e81359 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 14:20:37 +0000 Subject: [PATCH 20/27] update --- utils/tests_fetcher.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index bb6cc22f401a..f4037cfb065b 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -930,10 +930,12 @@ def infer_tests_to_run( print(f"\n### IMPACTED FILES ###\n{_print_list(impacted_files)}") # Grab the corresponding test files: + """ if any(x in modified_files for x in ["setup.py"]): test_files_to_run = ["tests", "examples"] + """ # in order to trigger pipeline tests even if no code change at all - elif "tests/utils/tiny_model_summary.json" in modified_files: + if "tests/utils/tiny_model_summary.json" in modified_files: test_files_to_run = ["tests"] any(f.split(os.path.sep)[0] == "utils" for f in modified_files) else: From 0ce97a13abe766a4ef743e6c5bf70428f91ec141 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 14:22:46 +0000 Subject: [PATCH 21/27] update --- utils/tests_fetcher.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index f4037cfb065b..02107566868c 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -822,6 +822,7 @@ def is_test(fname): # add entire core pipline modules instead pipeline_tests.extend([PATH_TO_TESTS / f"pipelines/{pipe}" for pipe in IMPORTANT_PIPELINES]) test_map["pipelines"] = pipeline_tests + import ipdb; ipdb.set_trace() return test_map From 9f4c5db02cd9ec1839bda38e02715328244608e4 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 16:48:18 +0000 Subject: [PATCH 22/27] update --- utils/tests_fetcher.py | 57 ++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index 02107566868c..4e77a886f83b 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -807,23 +807,6 @@ def is_test(fname): # Build the test map test_map = {module: [f for f in deps if is_test(f)] for module, deps in reverse_map.items()} - # Always test core pipelines - if "pipelines" not in test_map: - test_map["pipelines"] = [PATH_TO_TESTS / f"pipelines/{pipe}" for pipe in IMPORTANT_PIPELINES] - - else: - pipeline_tests = [] - # first remove individual test files from core pipeline modules that might have been added - for pipe in test_map["pipelines"]: - if Path(pipe).parts(2) in IMPORTANT_PIPELINES: - continue - pipeline_tests.append(pipe) - - # add entire core pipline modules instead - pipeline_tests.extend([PATH_TO_TESTS / f"pipelines/{pipe}" for pipe in IMPORTANT_PIPELINES]) - test_map["pipelines"] = pipeline_tests - import ipdb; ipdb.set_trace() - return test_map def check_imports_all_exist(): @@ -849,7 +832,37 @@ def _print_list(l) -> str: return "\n".join([f"- {f}" for f in l]) -def create_json_map(test_files_to_run: List[str], json_output_file: str): +def update_test_map_with_core_pipelines(json_output_file: str): + print(f"\n### ADD CORE PIPELINE TESTS ###\n{_print_list(IMPORTANT_PIPELINES)}") + with open(json_output_file, 'rb') as fp: + test_map = json.load(fp) + + # Add core pipelines as their own test group + test_map["core_pipelines"] = " ".join(sorted([str(PATH_TO_TESTS / f"pipelines/{pipe}") for pipe in IMPORTANT_PIPELINES])) + + # If there are no existing pipeline tests save the map + if "pipelines" not in test_map: + with open(json_output_file, "w", encoding="UTF-8") as fp: + json.dump(test_map, fp, ensure_ascii=False) + + pipeline_tests = test_map.pop("pipelines") + pipeline_tests = pipeline_tests.split(" ") + + # Remove core pipeline tests from the fetched pipeline tests + updated_pipeline_tests = [] + for pipe in pipeline_tests: + if pipe == "tests/pipelines" or Path(pipe).parts[2] in IMPORTANT_PIPELINES: + continue + updated_pipeline_tests.append(pipe) + + if len(updated_pipeline_tests) > 0: + test_map["pipelines"] = " ".join(sorted(updated_pipeline_tests)) + + with open(json_output_file, "w", encoding="UTF-8") as fp: + json.dump(test_map, fp, ensure_ascii=False) + + +def create_json_map(test_files_to_run: List[str], json_output_file: Optional[str] = None): """ Creates a map from a list of tests to run to easily split them by category, when running parallelism of slow tests. @@ -886,10 +899,10 @@ def create_json_map(test_files_to_run: List[str], json_output_file: str): # sort the keys & values keys = sorted(test_map.keys()) test_map = {k: " ".join(sorted(test_map[k])) for k in keys} + with open(json_output_file, "w", encoding="UTF-8") as fp: json.dump(test_map, fp, ensure_ascii=False) - def infer_tests_to_run( output_file: str, diff_with_last_commit: bool = False, @@ -931,10 +944,9 @@ def infer_tests_to_run( print(f"\n### IMPACTED FILES ###\n{_print_list(impacted_files)}") # Grab the corresponding test files: - """ if any(x in modified_files for x in ["setup.py"]): test_files_to_run = ["tests", "examples"] - """ + # in order to trigger pipeline tests even if no code change at all if "tests/utils/tiny_model_summary.json" in modified_files: test_files_to_run = ["tests"] @@ -1096,6 +1108,8 @@ def parse_commit_message(commit_message: str) -> Dict[str, bool]: json_output_file=args.json_output_file, ) filter_tests(args.output_file, ["repo_utils"]) + update_test_map_with_core_pipelines(json_output_file=args.json_output_file) + except Exception as e: print(f"\nError when trying to grab the relevant tests: {e}\n\nRunning all tests.") commit_flags["test_all"] = True @@ -1109,3 +1123,4 @@ def parse_commit_message(commit_message: str) -> Dict[str, bool]: test_files_to_run = get_all_tests() create_json_map(test_files_to_run, args.json_output_file) + update_test_map_with_core_pipelines(json_output_file=args.json_output_file) \ No newline at end of file From d8a27c539ecc101f30f1b5eaf7a1a88dc46c49c0 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 17:08:38 +0000 Subject: [PATCH 23/27] update --- utils/tests_fetcher.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index 4e77a886f83b..ffeac6acd0ae 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -1115,6 +1115,7 @@ def parse_commit_message(commit_message: str) -> Dict[str, bool]: commit_flags["test_all"] = True if commit_flags["test_all"]: + import ipdb; ipdb.set_trace() with open(args.output_file, "w", encoding="utf-8") as f: f.write("tests") example_file = Path(args.output_file).parent / "examples_test_list.txt" From 43faeb5539cc9788cba740d243766d1dcd171752 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 17:10:08 +0000 Subject: [PATCH 24/27] update --- utils/tests_fetcher.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index ffeac6acd0ae..177967cf1048 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -1032,6 +1032,7 @@ def parse_commit_message(commit_message: str) -> Dict[str, bool]: `Dict[str, bool]`: A dictionary of strings to bools with keys the following keys: `"skip"`, `"test_all_models"` and `"test_all"`. """ + import ipdb; ipdb.set_trace() if commit_message is None: return {"skip": False, "no_filter": False, "test_all": False} From 956e1966ceaa068b78df861171c1d0f62135cc15 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 30 Nov 2023 17:12:40 +0000 Subject: [PATCH 25/27] update --- utils/tests_fetcher.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index 177967cf1048..4e77a886f83b 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -1032,7 +1032,6 @@ def parse_commit_message(commit_message: str) -> Dict[str, bool]: `Dict[str, bool]`: A dictionary of strings to bools with keys the following keys: `"skip"`, `"test_all_models"` and `"test_all"`. """ - import ipdb; ipdb.set_trace() if commit_message is None: return {"skip": False, "no_filter": False, "test_all": False} @@ -1116,7 +1115,6 @@ def parse_commit_message(commit_message: str) -> Dict[str, bool]: commit_flags["test_all"] = True if commit_flags["test_all"]: - import ipdb; ipdb.set_trace() with open(args.output_file, "w", encoding="utf-8") as f: f.write("tests") example_file = Path(args.output_file).parent / "examples_test_list.txt" From 4e2fdadf5a0d7a53427b1670c0fefa7432e67aa4 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Sat, 2 Dec 2023 06:41:24 +0000 Subject: [PATCH 26/27] quality fix --- utils/tests_fetcher.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index 4e77a886f83b..dfa8f90837c5 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -83,6 +83,7 @@ "wuerstchen", ] + @contextmanager def checkout_commit(repo: Repo, commit_id: str): """ @@ -777,9 +778,7 @@ def create_reverse_dependency_map() -> Dict[str, List[str]]: return reverse_map -def create_module_to_test_map( - reverse_map: Dict[str, List[str]] = None -) -> Dict[str, List[str]]: +def create_module_to_test_map(reverse_map: Dict[str, List[str]] = None) -> Dict[str, List[str]]: """ Extract the tests from the reverse_dependency_map and potentially filters the model tests. @@ -809,6 +808,7 @@ def is_test(fname): return test_map + def check_imports_all_exist(): """ Isn't used per se by the test fetcher but might be used later as a quality check. Putting this here for now so the @@ -834,11 +834,13 @@ def _print_list(l) -> str: def update_test_map_with_core_pipelines(json_output_file: str): print(f"\n### ADD CORE PIPELINE TESTS ###\n{_print_list(IMPORTANT_PIPELINES)}") - with open(json_output_file, 'rb') as fp: + with open(json_output_file, "rb") as fp: test_map = json.load(fp) # Add core pipelines as their own test group - test_map["core_pipelines"] = " ".join(sorted([str(PATH_TO_TESTS / f"pipelines/{pipe}") for pipe in IMPORTANT_PIPELINES])) + test_map["core_pipelines"] = " ".join( + sorted([str(PATH_TO_TESTS / f"pipelines/{pipe}") for pipe in IMPORTANT_PIPELINES]) + ) # If there are no existing pipeline tests save the map if "pipelines" not in test_map: @@ -903,6 +905,7 @@ def create_json_map(test_files_to_run: List[str], json_output_file: Optional[str with open(json_output_file, "w", encoding="UTF-8") as fp: json.dump(test_map, fp, ensure_ascii=False) + def infer_tests_to_run( output_file: str, diff_with_last_commit: bool = False, @@ -994,7 +997,6 @@ def infer_tests_to_run( def filter_tests(output_file: str, filters: List[str]): - """ Reads the content of the output file and filters out all the tests in a list of given folders. @@ -1123,4 +1125,4 @@ def parse_commit_message(commit_message: str) -> Dict[str, bool]: test_files_to_run = get_all_tests() create_json_map(test_files_to_run, args.json_output_file) - update_test_map_with_core_pipelines(json_output_file=args.json_output_file) \ No newline at end of file + update_test_map_with_core_pipelines(json_output_file=args.json_output_file) From 90d1e24c9f390168413e3b0afdd97849ddc63d5d Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Mon, 4 Dec 2023 06:17:12 +0000 Subject: [PATCH 27/27] fix failure reporting --- .github/workflows/pr_test_fetcher.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr_test_fetcher.yml b/.github/workflows/pr_test_fetcher.yml index 622cd489e843..6c5d0f1c248b 100644 --- a/.github/workflows/pr_test_fetcher.yml +++ b/.github/workflows/pr_test_fetcher.yml @@ -111,7 +111,7 @@ jobs: continue-on-error: true run: | cat reports/${{ matrix.modules }}_tests_cpu_stats.txt - cat reports/${{ matrix.modules }}_tests_cpu/failures_short.txt + cat reports/${{ matrix.modules }}_tests_cpu_failures_short.txt - name: Test suite reports artifacts if: ${{ always() }}