pyresearch commited on
Commit
40893c3
·
verified ·
1 Parent(s): b61993d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -1,10 +1,7 @@
1
  import streamlit as st
2
- from transformers import AutoTokenizer, AutoModelForCausalLM
3
- from transformers import AutoTokenizer
4
-
5
  import torch
6
 
7
-
8
  # Load the Phi 2 model and tokenizer
9
  tokenizer = AutoTokenizer.from_pretrained(
10
  "microsoft/phi-2",
@@ -17,6 +14,9 @@ model = AutoModelForCausalLM.from_pretrained(
17
  trust_remote_code=True
18
  )
19
 
 
 
 
20
  # Streamlit UI
21
  st.title("Microsoft Phi 2 Streamlit App")
22
 
@@ -36,4 +36,4 @@ if st.button("Generate Output"):
36
 
37
  output = tokenizer.decode(output_ids[0][token_ids.size(1):])
38
  st.text("Generated Output:")
39
- st.write(output)
 
1
  import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM, disk_offload
 
 
3
  import torch
4
 
 
5
  # Load the Phi 2 model and tokenizer
6
  tokenizer = AutoTokenizer.from_pretrained(
7
  "microsoft/phi-2",
 
14
  trust_remote_code=True
15
  )
16
 
17
+ # Offload the model to disk
18
+ model, tokenizer = disk_offload(model, tokenizer)
19
+
20
  # Streamlit UI
21
  st.title("Microsoft Phi 2 Streamlit App")
22
 
 
36
 
37
  output = tokenizer.decode(output_ids[0][token_ids.size(1):])
38
  st.text("Generated Output:")
39
+ st.write(output)