Arijit-07 commited on
Commit
908dd05
Β·
1 Parent(s): 369766c

fix: add transformers fallback for unsloth module in demo_llm.py

Browse files
Files changed (1) hide show
  1. demo_llm.py +26 -11
demo_llm.py CHANGED
@@ -54,18 +54,33 @@ console = Console(
54
  # ─── Model loading ────────────────────────────────────────────────────────────
55
 
56
  def load_model():
57
- from unsloth import FastLanguageModel
58
- import torch
59
-
60
  console.print("[cyan]Loading ARIA fine-tuned model...[/cyan]")
61
- model, tokenizer = FastLanguageModel.from_pretrained(
62
- model_name=MODEL_REPO,
63
- max_seq_length=2048,
64
- load_in_4bit=True,
65
- token=HF_TOKEN,
66
- )
67
- FastLanguageModel.for_inference(model)
68
- console.print(f"[green]βœ“ Model loaded: {MODEL_REPO}[/green]")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  return model, tokenizer
70
 
71
  # ─── System prompt ────────────────────────────────────────────────────────────
 
54
  # ─── Model loading ────────────────────────────────────────────────────────────
55
 
56
  def load_model():
 
 
 
57
  console.print("[cyan]Loading ARIA fine-tuned model...[/cyan]")
58
+ try:
59
+ from unsloth import FastLanguageModel
60
+ import torch
61
+
62
+ model, tokenizer = FastLanguageModel.from_pretrained(
63
+ model_name=MODEL_REPO,
64
+ max_seq_length=2048,
65
+ load_in_4bit=True,
66
+ token=HF_TOKEN,
67
+ )
68
+ FastLanguageModel.for_inference(model)
69
+ console.print(f"[green]βœ“ Model loaded via Unsloth: {MODEL_REPO}[/green]")
70
+ except ModuleNotFoundError:
71
+ console.print("[yellow]! Unsloth not found. Falling back to standard transformers...[/yellow]")
72
+ from transformers import AutoModelForCausalLM, AutoTokenizer
73
+ import torch
74
+
75
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_REPO, token=HF_TOKEN)
76
+ model = AutoModelForCausalLM.from_pretrained(
77
+ MODEL_REPO,
78
+ token=HF_TOKEN,
79
+ device_map="auto",
80
+ torch_dtype=torch.float16,
81
+ )
82
+ console.print(f"[green]βœ“ Model loaded via Transformers: {MODEL_REPO}[/green]")
83
+
84
  return model, tokenizer
85
 
86
  # ─── System prompt ────────────────────────────────────────────────────────────