| 20 | |
| 21 | |
| 22 | class Categorizer: |
| 23 | def __init__(self, path, category="Uncategorized", use_classifier: bool = False): |
| 24 | self.cache = get_commit_data_cache() |
| 25 | self.commits = CommitList.from_existing(path) |
| 26 | if use_classifier: |
| 27 | print("Using a classifier to aid with categorization.") |
| 28 | device = "cuda" if torch.cuda.is_available() else "cpu" |
| 29 | classifier_config = CategoryConfig(common.categories) |
| 30 | author_map = get_author_map( |
| 31 | Path("results/classifier"), regen_data=False, assert_stored=True |
| 32 | ) |
| 33 | file_map = get_file_map( |
| 34 | Path("results/classifier"), regen_data=False, assert_stored=True |
| 35 | ) |
| 36 | self.classifier = CommitClassifier( |
| 37 | XLMR_BASE, author_map, file_map, classifier_config |
| 38 | ).to(device) |
| 39 | self.classifier.load_state_dict( |
| 40 | torch.load(Path("results/classifier/commit_classifier.pt")) |
| 41 | ) |
| 42 | self.classifier.eval() |
| 43 | else: |
| 44 | self.classifier = None |
| 45 | # Special categories: 'Uncategorized' |
| 46 | # All other categories must be real |
| 47 | self.category = category |
| 48 | |
| 49 | def categorize(self): |
| 50 | commits = self.commits.filter(category=self.category) |
| 51 | total_commits = len(self.commits.commits) |
| 52 | already_done = total_commits - len(commits) |
| 53 | i = 0 |
| 54 | while i < len(commits): |
| 55 | cur_commit = commits[i] |
| 56 | next_commit = commits[i + 1] if i + 1 < len(commits) else None |
| 57 | jump_to = self.handle_commit( |
| 58 | cur_commit, already_done + i + 1, total_commits, commits |
| 59 | ) |
| 60 | |
| 61 | # Increment counter |
| 62 | if jump_to is not None: |
| 63 | i = jump_to |
| 64 | elif next_commit is None: |
| 65 | i = len(commits) |
| 66 | else: |
| 67 | i = commits.index(next_commit) |
| 68 | |
| 69 | def features(self, commit): |
| 70 | return self.cache.get(commit.commit_hash) |
| 71 | |
| 72 | def potential_reverts_of(self, commit, commits): |
| 73 | submodule_update_str = [ |
| 74 | "Update TensorPipe submodule", |
| 75 | "Updating submodules", |
| 76 | "Automated submodule update", |
| 77 | ] |
| 78 | if any(a in commit.title for a in submodule_update_str): |
| 79 | return [] |
no outgoing calls
no test coverage detected
searching dependent graphs…