Views
No views yet
bfloat16 compute types and Hugging Face's high-speed Rust-based downloader for maximum performance.pip. However, for a stable environment, ensure you have the following installed:torch (Compiled with CUDA support)transformersbitsandbytesacceleratehf_transferinference.py)inference.py and paste the following code into it. You can run this directly in your terminal or inside a Jupyter/Colab notebook.1import os
2import sys
3import subprocess
4
5# --- ENABLE ULTRA-FAST DOWNLOADS ---
6# This tells Hugging Face to use the Rust-based multi-threaded downloader.
7# It can increase download speeds by 10x-50x for massive models like this 235B model.
8os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
9
10# --- DEPENDENCY CHECK ---
11# Modal/Colab notebooks might not have quantization libraries pre-installed.
12# This block ensures required packages are installed before running.
13try:
14 import bitsandbytes
15 import accelerate
16 import hf_transfer
17except ImportError:
18 print("Missing packages. Installing 'bitsandbytes', 'accelerate', and 'hf_transfer'...")
19 subprocess.check_call([sys.executable, "-m", "pip", "install", "-U", "-q", "bitsandbytes", "accelerate", "hf-transfer"])
20
21 # CRITICAL FIX: Tell Python to refresh its package cache so it sees the newly installed packages
22 import importlib
23 import site
24 importlib.invalidate_caches()
25 print("Installation complete!")
26
27from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
28import torch
29
30# --- HUGGING FACE SETUP ---
31# Path to your fine-tuned VERBAREX model.
32# Note: Ensure this points to the exact repo name where your fine-tune is hosted.
33model_id = "Qwen/Qwen3-235B-A22B"
34
35print(f"Downloading/Loading fine-tuned model from Hugging Face: {model_id}...")
36print("If downloading, hf_transfer is active. This will be much faster!")
37
38# Load tokenizer
39tokenizer = AutoTokenizer.from_pretrained(
40 model_id,
41 trust_remote_code=True,
42 use_fast=False
43)
44
45# --- OPTIMIZED FOR 1x H200 141GB ---
46# We compress the ~470GB model to 4-bit (~130GB) so it fits entirely on the GPU.
47# Switching to bfloat16 is natively supported by Hopper (H200) and highly recommended.
48bnb_config = BitsAndBytesConfig(
49 load_in_4bit=True,
50 bnb_4bit_compute_dtype=torch.bfloat16, # <-- Optimized for H200
51 bnb_4bit_use_double_quant=True,
52 bnb_4bit_quant_type="nf4",
53 llm_int8_enable_fp32_cpu_offload=True # <-- Kept for safety if KV cache slightly exceeds 141GB
54)
55
56# Load model safely
57model = AutoModelForCausalLM.from_pretrained(
58 model_id,
59 device_map="auto",
60 quantization_config=bnb_config,
61 torch_dtype=torch.bfloat16, # <-- Optimized for H200
62 trust_remote_code=True
63)
64
65print("Fine-tuned model loaded successfully! Generating text...")
66
67# --- PROMPT & GENERATION ---
68# Define the system prompt and the user's question
69messages = [
70 {"role": "system", "content": "You are LuminoLex-Aura an AI model developed by VERBAREX."},
71 {"role": "user", "content": "Greetings! Could you introduce yourself, tell me who created you, and explain what kind of advanced tasks you are capable of handling?"}
72]
73
74# Apply the model's specific chat format
75input_ids = tokenizer.apply_chat_template(
76 messages,
77 tokenize=True,
78 add_generation_prompt=True,
79 return_tensors="pt"
80).to(model.device)
81
82# Generate the response
83outputs = model.generate(
84 input_ids,
85 max_new_tokens=256, # Adjusted to allow for a detailed introduction
86 do_sample=True,
87 temperature=0.7,
88 top_p=0.95
89)
90
91# Slice off the input prompt so we only print the model's new response
92input_length = input_ids.shape[1]
93generated_tokens = outputs[0][input_length:]
94
95print("\n--- OUTPUT ---")
96print(tokenizer.decode(generated_tokens, skip_special_tokens=True))