Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize compute_anomaly_score by using torch native funcrtions #141

Merged
merged 1 commit into from
Mar 10, 2022
Merged

optimize compute_anomaly_score by using torch native funcrtions #141

merged 1 commit into from
Mar 10, 2022

Conversation

alexriedel1
Copy link
Contributor

Hey,
I realized that the compute_anomy_score method

def compute_anomaly_score(patch_scores: torch.Tensor) -> torch.Tensor:
can be optimized by using torch native functions that might vectorize better.

Using a GPU, the execution time reduces from 0.17330350000000116s to 0.00022549999999910142s (~700x faster)

Copy link
Contributor

@samet-akcay samet-akcay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alexriedel1! That's a good catch! We'd be able to merge it after @djdameln approves the PR

@alexriedel1
Copy link
Contributor Author

alexriedel1 commented Mar 9, 2022

Thanks @alexriedel1! That's a good catch! We'd be able to merge it after @djdameln approves the PR

Theres one more thing I'd like to adress: torch.cdist() is slow (especially for large tensors) (pytorch/pytorch#15253)

distances = torch.cdist(embedding, self.memory_bank, p=2.0) # euclidean norm

This cdist implementation is fast: pytorch/pytorch#15253 (comment)

Maybe you can think about using the version mentioned above. I can create another pull request for this.

Copy link
Contributor

@djdameln djdameln left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing this @alexriedel1!

@samet-akcay
Copy link
Contributor

@alexriedel1, would you like to address that in a separate PR, or in this one? If the former, I could merge this one.

@alexriedel1
Copy link
Contributor Author

@alexriedel1, would you like to address that in a separate PR, or in this one? If the former, I could merge this one.

Let me do another PR so you can merge this one

@samet-akcay samet-akcay merged commit cebc3a4 into openvinotoolkit:development Mar 10, 2022
@alexriedel1 alexriedel1 deleted the optimized_patchcore branch March 10, 2022 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants