rohansampath commited on
Commit
008b5f1
·
verified ·
1 Parent(s): 274521a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -15,13 +15,23 @@ from transformers import AutoTokenizer, AutoModel
15
  hf_token = os.getenv("HF_TOKEN_READ_WRITE") # Read the token from Secrets
16
  login(hf_token)
17
 
 
 
 
 
 
 
18
  # ---------------------------------------------------------------------------
19
  # 1. Define model name and load model/tokenizer
20
  # ---------------------------------------------------------------------------
21
  model_name = "mistralai/Mistral-7B-Instruct-v0.3" # fictional placeholder
22
 
23
  tokenizer = AutoTokenizer.from_pretrained(model_name)
24
- model = AutoModelForCausalLM.from_pretrained(model_name)
 
 
 
 
25
 
26
  # ---------------------------------------------------------------------------
27
  # 2. Define a tiny "dataset" for demonstration
 
15
  hf_token = os.getenv("HF_TOKEN_READ_WRITE") # Read the token from Secrets
16
  login(hf_token)
17
 
18
+ if torch.cuda.is_available():
19
+ print("✅ GPU is available")
20
+ print("GPU Name:", torch.cuda.get_device_name(0))
21
+ else:
22
+ print("❌ No GPU available")
23
+
24
  # ---------------------------------------------------------------------------
25
  # 1. Define model name and load model/tokenizer
26
  # ---------------------------------------------------------------------------
27
  model_name = "mistralai/Mistral-7B-Instruct-v0.3" # fictional placeholder
28
 
29
  tokenizer = AutoTokenizer.from_pretrained(model_name)
30
+ device = "cuda" if torch.cuda.is_available() else "cpu"
31
+ model = AutoModelForCausalLM.from_pretrained(model_name, token=hf_token, torch_dtype=torch.float16, device_map="auto").to(device)
32
+
33
+ print(f"✅ Model loaded on {device}")
34
+ #model = AutoModelForCausalLM.from_pretrained(model_name)
35
 
36
  # ---------------------------------------------------------------------------
37
  # 2. Define a tiny "dataset" for demonstration