Upload app.py
Browse files
app.py
CHANGED
@@ -366,23 +366,26 @@ def load_model():
|
|
366 |
classifier_adapter_repo = "arvindsuresh-math/phi-4-error-binary-classifier"
|
367 |
base_phi_model = "microsoft/Phi-4-mini-instruct"
|
368 |
|
369 |
-
|
|
|
370 |
quantization_config = BitsAndBytesConfig(
|
371 |
load_in_4bit=True,
|
372 |
bnb_4bit_quant_type="nf4",
|
373 |
-
bnb_4bit_compute_dtype=DTYPE
|
374 |
-
|
375 |
classifier_backbone_base = AutoModelForCausalLM.from_pretrained(
|
376 |
base_phi_model,
|
377 |
quantization_config=quantization_config,
|
378 |
-
device_map="
|
379 |
-
trust_remote_code=
|
380 |
-
|
|
|
381 |
|
382 |
classifier_tokenizer = AutoTokenizer.from_pretrained(
|
383 |
base_phi_model,
|
384 |
-
trust_remote_code=
|
385 |
-
|
|
|
386 |
classifier_tokenizer.padding_side = "left"
|
387 |
if classifier_tokenizer.pad_token is None:
|
388 |
classifier_tokenizer.pad_token = classifier_tokenizer.eos_token
|
@@ -411,7 +414,6 @@ def load_model():
|
|
411 |
def models_ready():
|
412 |
return all([gemma_model, gemma_tokenizer, classifier_model, classifier_tokenizer])
|
413 |
|
414 |
-
@spaces.GPU
|
415 |
def analyze_single(math_question: str, proposed_solution: str, debug: bool = False):
|
416 |
"""
|
417 |
Single (question, solution) classifier.
|
@@ -516,8 +518,6 @@ def analyze_single(math_question: str, proposed_solution: str, debug: bool = Fal
|
|
516 |
}
|
517 |
|
518 |
|
519 |
-
|
520 |
-
@spaces.GPU
|
521 |
def classify_solution(question: str, solution: str):
|
522 |
"""
|
523 |
Classify the math solution
|
|
|
366 |
classifier_adapter_repo = "arvindsuresh-math/phi-4-error-binary-classifier"
|
367 |
base_phi_model = "microsoft/Phi-4-mini-instruct"
|
368 |
|
369 |
+
# T4 does fp16 (not bf16)
|
370 |
+
DTYPE = torch.float16
|
371 |
quantization_config = BitsAndBytesConfig(
|
372 |
load_in_4bit=True,
|
373 |
bnb_4bit_quant_type="nf4",
|
374 |
+
bnb_4bit_compute_dtype=DTYPE,
|
375 |
+
)
|
376 |
classifier_backbone_base = AutoModelForCausalLM.from_pretrained(
|
377 |
base_phi_model,
|
378 |
quantization_config=quantization_config,
|
379 |
+
device_map={"": 0}, # single-GPU
|
380 |
+
trust_remote_code=False, # <-- avoid remote LossKwargs import
|
381 |
+
attn_implementation="sdpa",
|
382 |
+
)
|
383 |
|
384 |
classifier_tokenizer = AutoTokenizer.from_pretrained(
|
385 |
base_phi_model,
|
386 |
+
trust_remote_code=False # <-- match above
|
387 |
+
)
|
388 |
+
|
389 |
classifier_tokenizer.padding_side = "left"
|
390 |
if classifier_tokenizer.pad_token is None:
|
391 |
classifier_tokenizer.pad_token = classifier_tokenizer.eos_token
|
|
|
414 |
def models_ready():
|
415 |
return all([gemma_model, gemma_tokenizer, classifier_model, classifier_tokenizer])
|
416 |
|
|
|
417 |
def analyze_single(math_question: str, proposed_solution: str, debug: bool = False):
|
418 |
"""
|
419 |
Single (question, solution) classifier.
|
|
|
518 |
}
|
519 |
|
520 |
|
|
|
|
|
521 |
def classify_solution(question: str, solution: str):
|
522 |
"""
|
523 |
Classify the math solution
|