Spaces:
Runtime error
Runtime error
Commit ·
3dea6d8
1
Parent(s): 5b08636
try different
Browse files
app.py
CHANGED
|
@@ -21,7 +21,6 @@ app = FastAPI()
|
|
| 21 |
# // FOR RUNNING IN SPACES
|
| 22 |
model_name = "numind/NuExtract-1.5-tiny"
|
| 23 |
# Path inside your container
|
| 24 |
-
# MODEL_PATH = "/app/model_cache/models--numind--NuExtract-1.5-tiny/snapshots/df52efb3109d324cd52b30728f9e3fdedf19f742"
|
| 25 |
# If you used local_dir="model", snapshot_download will still create models--… subfolder.
|
| 26 |
# You can also symlink or copy it to /app/model directly in Dockerfile.
|
| 27 |
|
|
@@ -42,7 +41,6 @@ dtype = torch.float16 if device in ("mps", "cuda") else torch.float32
|
|
| 42 |
|
| 43 |
print("CUDA available:", torch.cuda.is_available()) # True
|
| 44 |
print("Device name:", torch.cuda.get_device_name(0))
|
| 45 |
-
# bnb_config = BitsAndBytesConfig(load_in_8bit=True)
|
| 46 |
|
| 47 |
|
| 48 |
# If lower memory usage needed:
|
|
@@ -50,7 +48,8 @@ print("Device name:", torch.cuda.get_device_name(0))
|
|
| 50 |
bnb_config = BitsAndBytesConfig(
|
| 51 |
load_in_4bit=True,
|
| 52 |
bnb_4bit_use_double_quant=True,
|
| 53 |
-
bnb_4bit_quant_type="nf4"
|
|
|
|
| 54 |
)
|
| 55 |
|
| 56 |
@app.on_event("startup")
|
|
@@ -123,7 +122,7 @@ def predict_NuExtract(texts, template, batch_size=1, max_length=5096, max_new_to
|
|
| 123 |
max_length=max_length
|
| 124 |
).to(device)
|
| 125 |
print(f"Generating outputs with model for batch {i//batch_size+1}...", flush=True)
|
| 126 |
-
ids = model.generate(**enc, max_new_tokens=max_new_tokens, num_beams=1, use_cache=
|
| 127 |
outputs += tokenizer.batch_decode(ids, skip_special_tokens=True)
|
| 128 |
print("Outputs generated.", flush=True)
|
| 129 |
elapsed = time.perf_counter() - start_time
|
|
|
|
| 21 |
# // FOR RUNNING IN SPACES
|
| 22 |
model_name = "numind/NuExtract-1.5-tiny"
|
| 23 |
# Path inside your container
|
|
|
|
| 24 |
# If you used local_dir="model", snapshot_download will still create models--… subfolder.
|
| 25 |
# You can also symlink or copy it to /app/model directly in Dockerfile.
|
| 26 |
|
|
|
|
| 41 |
|
| 42 |
print("CUDA available:", torch.cuda.is_available()) # True
|
| 43 |
print("Device name:", torch.cuda.get_device_name(0))
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
# If lower memory usage needed:
|
|
|
|
| 48 |
bnb_config = BitsAndBytesConfig(
|
| 49 |
load_in_4bit=True,
|
| 50 |
bnb_4bit_use_double_quant=True,
|
| 51 |
+
bnb_4bit_quant_type="nf4",
|
| 52 |
+
bnb_4bit_compute_dtype=torch.float16
|
| 53 |
)
|
| 54 |
|
| 55 |
@app.on_event("startup")
|
|
|
|
| 122 |
max_length=max_length
|
| 123 |
).to(device)
|
| 124 |
print(f"Generating outputs with model for batch {i//batch_size+1}...", flush=True)
|
| 125 |
+
ids = model.generate(**enc, max_new_tokens=max_new_tokens, num_beams=1, use_cache=False)
|
| 126 |
outputs += tokenizer.batch_decode(ids, skip_special_tokens=True)
|
| 127 |
print("Outputs generated.", flush=True)
|
| 128 |
elapsed = time.perf_counter() - start_time
|