Commit ·
f7f6f04
1
Parent(s): a809234
ZeroGPU 0.1
Browse files- core/compressor.py +2 -1
- models/model_loader.py +1 -1
- requirements.txt +2 -1
core/compressor.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import torch
|
|
|
|
| 2 |
import config
|
| 3 |
from core.tokenizer_utils import count_tokens
|
| 4 |
from models.model_loader import get_llm
|
|
@@ -12,7 +13,7 @@ TEXT:
|
|
| 12 |
|
| 13 |
COMPRESSED:"""
|
| 14 |
|
| 15 |
-
|
| 16 |
def _generate(prompt: str) -> str:
|
| 17 |
model, tokenizer = get_llm()
|
| 18 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
|
|
|
| 1 |
import torch
|
| 2 |
+
import spaces
|
| 3 |
import config
|
| 4 |
from core.tokenizer_utils import count_tokens
|
| 5 |
from models.model_loader import get_llm
|
|
|
|
| 13 |
|
| 14 |
COMPRESSED:"""
|
| 15 |
|
| 16 |
+
@spaces.GPU
|
| 17 |
def _generate(prompt: str) -> str:
|
| 18 |
model, tokenizer = get_llm()
|
| 19 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
models/model_loader.py
CHANGED
|
@@ -43,7 +43,7 @@ def switch_llm(model_id: str) -> str:
|
|
| 43 |
def _load_llm(model_id: str):
|
| 44 |
"""Load model + its paired tokenizer. Both come from the same model_id."""
|
| 45 |
global _llm, _tokenizer, _current_model_id
|
| 46 |
-
_tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 47 |
_llm = AutoModelForCausalLM.from_pretrained(
|
| 48 |
model_id,
|
| 49 |
torch_dtype=torch.float32,
|
|
|
|
| 43 |
def _load_llm(model_id: str):
|
| 44 |
"""Load model + its paired tokenizer. Both come from the same model_id."""
|
| 45 |
global _llm, _tokenizer, _current_model_id
|
| 46 |
+
_tokenizer = AutoTokenizer.from_pretrained(model_id).to("cuda")
|
| 47 |
_llm = AutoModelForCausalLM.from_pretrained(
|
| 48 |
model_id,
|
| 49 |
torch_dtype=torch.float32,
|
requirements.txt
CHANGED
|
@@ -5,4 +5,5 @@ torch>=2.2.0
|
|
| 5 |
numpy>=1.26.0
|
| 6 |
pandas>=2.0.0
|
| 7 |
accelerate>=0.30.0
|
| 8 |
-
huggingface_hub<2.0
|
|
|
|
|
|
| 5 |
numpy>=1.26.0
|
| 6 |
pandas>=2.0.0
|
| 7 |
accelerate>=0.30.0
|
| 8 |
+
huggingface_hub<2.0
|
| 9 |
+
spaces==0.50.4
|