feat(medcat): CU-869cw9zmj Improve inference speed#410
Merged
Conversation
| prev_right = tokens_right | ||
|
|
||
| # Center is identical for all window sizes, only compute once | ||
| if center_vecs is None: |
Collaborator
There was a problem hiding this comment.
Minor feeling that this might flow better - can do centre tokens on it's own outside of the loop?
Instead of every window doing the check.
prev_left_vecs: list[np.ndarray] = []
prev_right_vecs: list[np.ndarray] = []
# Calc center vecs once outside the loop?
if not self.config.context_ignore_center_tokens:
tokens_center = self.get_context_tokens(
entity, doc, sorted_contexts[0], per_doc_valid_token_cache)[1] # or whatever is the best way
center_vecs = list(
self._preprocess_center_tokens(cui, tokens_center))
else:
center_vecs = []
for context_type, window_size in sorted_contexts:
# do everything other than the center_vecs calculation
Collaborator
Author
There was a problem hiding this comment.
Yeah, good point. If it's only done once, why do it in the loop at all!
Collaborator
Author
There was a problem hiding this comment.
Well, turns out the reason is that the centre tokens aren't available before you get to the loop!
But I do think it logically belongs outside the loop still.
alhendrickson
approved these changes
Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves inference speed somewhat (around 10%) by:
Using a more efficient unitvec calculation