Spaces:
Sleeping
Sleeping
Register generate() with @spaces.GPU for ZeroGPU
Browse files- app.py +8 -0
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -12,6 +12,13 @@ from huggingface_hub import hf_hub_download
|
|
| 12 |
from helioslm_v5.configs.config_v5 import HeliosLMv5Config
|
| 13 |
from helioslm_v5.src.model_v5 import HeliosLMv5
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
REPO = "chienhsinlin/helioslm"
|
| 16 |
CKPT = "toy/toy_v5.13.pt"
|
| 17 |
# char-ascii tokenizer: id = ord(c); 1021-1023 are PAD/EOS/BOS
|
|
@@ -29,6 +36,7 @@ def encode(text):
|
|
| 29 |
return [ord(c) for c in text if ord(c) < SPECIAL_MIN]
|
| 30 |
|
| 31 |
|
|
|
|
| 32 |
def generate(prompt, max_new_tokens, temperature, top_p, use_mtp):
|
| 33 |
ids = encode(prompt)
|
| 34 |
if not ids:
|
|
|
|
| 12 |
from helioslm_v5.configs.config_v5 import HeliosLMv5Config
|
| 13 |
from helioslm_v5.src.model_v5 import HeliosLMv5
|
| 14 |
|
| 15 |
+
try: # ZeroGPU Spaces require at least one @spaces.GPU function
|
| 16 |
+
import spaces
|
| 17 |
+
gpu = spaces.GPU(duration=30)
|
| 18 |
+
except ImportError:
|
| 19 |
+
def gpu(fn):
|
| 20 |
+
return fn
|
| 21 |
+
|
| 22 |
REPO = "chienhsinlin/helioslm"
|
| 23 |
CKPT = "toy/toy_v5.13.pt"
|
| 24 |
# char-ascii tokenizer: id = ord(c); 1021-1023 are PAD/EOS/BOS
|
|
|
|
| 36 |
return [ord(c) for c in text if ord(c) < SPECIAL_MIN]
|
| 37 |
|
| 38 |
|
| 39 |
+
@gpu
|
| 40 |
def generate(prompt, max_new_tokens, temperature, top_p, use_mtp):
|
| 41 |
ids = encode(prompt)
|
| 42 |
if not ids:
|
requirements.txt
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
torch==2.13.0
|
| 2 |
huggingface_hub
|
|
|
|
|
|
| 1 |
torch==2.13.0
|
| 2 |
huggingface_hub
|
| 3 |
+
spaces
|