Skip to content

Commit

Permalink
Fix run mode of model (#61)
Browse files Browse the repository at this point in the history
added code to run the model in inference_mode.
  • Loading branch information
jsrinivasa authored Mar 1, 2024
1 parent ff9e843 commit 09bb969
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions backend/models/interfaces/model_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def answer_question(question, answer_text, model, tokenizer):
# There should be a segment_id for every input token.
assert len(segment_ids) == len(input_ids)

outputs = model(torch.tensor([input_ids]), # The tokens representing our input text.
with torch.inference_mode(): ## Run the model in inference mode
outputs = model(torch.tensor([input_ids]), # The tokens representing our input text.
# The segment IDs to differentiate question from answer_text
token_type_ids=torch.tensor([segment_ids]),
return_dict=True)
Expand Down Expand Up @@ -656,4 +657,4 @@ def partial_ratio(s1, s2):
max_distance = max(max_distance, len(shorter) - distance)

ratio = (max_distance / len(shorter)) * 100
return ratio
return ratio

0 comments on commit 09bb969

Please sign in to comment.