MarioBarbeque commited on
Commit
04337d8
·
1 Parent(s): 86d85c0

move model and input ids to GPU

Browse files
Files changed (2) hide show
  1. app.py +2 -2
  2. model.py +2 -2
app.py CHANGED
@@ -110,8 +110,8 @@ def get_stream_warning_error(stream):
110
  # return chat_completion
111
 
112
  def model_inference(messages):
113
- # input_ids = tokenizer(get_last_question(), return_tensors="pt").input_ids.to("cuda") # tokenize the input and put it on the GPU
114
- input_ids = tokenizer(get_last_question(), return_tensors="pt").input_ids # move to GPU eventually
115
  outputs = model.generate(input_ids)
116
  for chunk in tokenizer.decode(outputs[0], skip_special_tokens=True):
117
  yield chunk # yield each chunk of the predicted string character by character
 
110
  # return chat_completion
111
 
112
  def model_inference(messages):
113
+ input_ids = tokenizer(get_last_question(), return_tensors="pt").input_ids.to("cuda") # tokenize the input and put it on the GPU
114
+ # input_ids = tokenizer(get_last_question(), return_tensors="pt").input_ids # testing on CPU
115
  outputs = model.generate(input_ids)
116
  for chunk in tokenizer.decode(outputs[0], skip_special_tokens=True):
117
  yield chunk # yield each chunk of the predicted string character by character
model.py CHANGED
@@ -27,8 +27,8 @@ class InferenceBuilder:
27
  # cannot directly use @st.cache_resource on a method (function within a class) that has a self argument
28
  @st.cache_resource # https://docs.streamlit.io/develop/concepts/architecture/caching
29
  def load_and_cache_model(model_name):
30
- # model = T5ForConditionalGeneration.from_pretrained(model_name).to("cuda") # put the model on our Space's GPU
31
- model = T5ForConditionalGeneration.from_pretrained(model_name) # move to GPU eventually
32
  return model
33
 
34
  return load_and_cache_model(model_name)
 
27
  # cannot directly use @st.cache_resource on a method (function within a class) that has a self argument
28
  @st.cache_resource # https://docs.streamlit.io/develop/concepts/architecture/caching
29
  def load_and_cache_model(model_name):
30
+ model = T5ForConditionalGeneration.from_pretrained(model_name).to("cuda") # put the model on our Space's GPU
31
+ # model = T5ForConditionalGeneration.from_pretrained(model_name) # testing on CPU
32
  return model
33
 
34
  return load_and_cache_model(model_name)