Spaces:
Running on Zero
Running on Zero
Daryl Lim Claude Opus 4.8 (1M context) commited on
Commit ·
607cea3
1
Parent(s): c15ff11
refactor: use concrete T5 types and run ty at full strictness
Browse filesAnnotate _load_tokenizer -> T5TokenizerFast and _load_model ->
T5ForConditionalGeneration (the concrete classes AutoTokenizer/
AutoModelForSeq2SeqLM return for this T5-derived model). Unlike the
PreTrainedModel base class, T5ForConditionalGeneration exposes
generate(), resolving the last call-non-callable warning. With zero
diagnostics remaining, drop the ty.toml [rules] warn-downgrades so ty
runs at default strictness and real type errors fail instead of being
masked.
Verified: ty "All checks passed!", ruff clean, 40 fast tests pass.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
app.py
CHANGED
|
@@ -10,7 +10,7 @@ from functools import lru_cache
|
|
| 10 |
import gradio as gr
|
| 11 |
import spaces
|
| 12 |
import torch
|
| 13 |
-
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer,
|
| 14 |
|
| 15 |
from langmap.langid_mapping import langid_to_language
|
| 16 |
|
|
@@ -25,7 +25,7 @@ def _get_device() -> torch.device:
|
|
| 25 |
|
| 26 |
|
| 27 |
@lru_cache(maxsize=1)
|
| 28 |
-
def _load_tokenizer() ->
|
| 29 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_fast=True)
|
| 30 |
if tokenizer is None:
|
| 31 |
raise RuntimeError(f"Failed to load tokenizer for {MODEL_NAME}")
|
|
@@ -33,7 +33,7 @@ def _load_tokenizer() -> PreTrainedTokenizerBase:
|
|
| 33 |
|
| 34 |
|
| 35 |
@lru_cache(maxsize=1)
|
| 36 |
-
def _load_model() ->
|
| 37 |
device = _get_device()
|
| 38 |
dtype = torch.float16 if device.type == "cuda" else torch.float32
|
| 39 |
return AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME, dtype=dtype).to(device)
|
|
|
|
| 10 |
import gradio as gr
|
| 11 |
import spaces
|
| 12 |
import torch
|
| 13 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, T5ForConditionalGeneration, T5TokenizerFast
|
| 14 |
|
| 15 |
from langmap.langid_mapping import langid_to_language
|
| 16 |
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
@lru_cache(maxsize=1)
|
| 28 |
+
def _load_tokenizer() -> T5TokenizerFast:
|
| 29 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_fast=True)
|
| 30 |
if tokenizer is None:
|
| 31 |
raise RuntimeError(f"Failed to load tokenizer for {MODEL_NAME}")
|
|
|
|
| 33 |
|
| 34 |
|
| 35 |
@lru_cache(maxsize=1)
|
| 36 |
+
def _load_model() -> T5ForConditionalGeneration:
|
| 37 |
device = _get_device()
|
| 38 |
dtype = torch.float16 if device.type == "cuda" else torch.float32
|
| 39 |
return AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME, dtype=dtype).to(device)
|
ty.toml
CHANGED
|
@@ -1,9 +1,2 @@
|
|
| 1 |
[environment]
|
| 2 |
python-version = "3.12"
|
| 3 |
-
|
| 4 |
-
[rules]
|
| 5 |
-
# Third-party libraries with missing or incomplete type stubs
|
| 6 |
-
unresolved-import = "warn"
|
| 7 |
-
unresolved-attribute = "warn"
|
| 8 |
-
call-non-callable = "warn"
|
| 9 |
-
invalid-argument-type = "warn"
|
|
|
|
| 1 |
[environment]
|
| 2 |
python-version = "3.12"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|