Views
No views yet
Qwen/Qwen3.8-27B large language model. Following the fine-tuning process on the main model, it was quantized on-the-fly using the bitsandbytes library and pushed directly to the Hugging Face Hub. The quantization reduces the model's memory footprint from approximately 54GB (in native 16-bit) down to roughly 14GB, making it strictly accessible for deployment and inference on hardware with constrained VRAM limits, such as a single 16GB GPU or Kaggle 2x T4 setups.Qwen/Qwen3.8-27B base model.Qwen/Qwen3.8-27Btransformers ecosystem utilizing bitsandbytes for 4-bit loading.CUDA Out of Memory exceptions.1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3
4model_id = "uzairkhanux/Qwen3.8-27B-FP4"
5
6# Configure FP4 Quantization WITH CPU Offloading capability
7quantization_config = BitsAndBytesConfig(
8 load_in_4bit=True,
9 bnb_4bit_quant_type="fp4",
10 bnb_4bit_compute_dtype=torch.float16,
11 bnb_4bit_use_double_quant=False,
12 llm_int8_enable_fp32_cpu_offload=True
13)
14
15# Apply safety buffers to prevent CUDA Out Of Memory spikes (e.g., for Kaggle 2x T4)
16memory_limits = {
17 0: "12GB",
18 1: "12GB",
19 "cpu": "25GB"
20}
21
22tokenizer = AutoTokenizer.from_pretrained(model_id)
23
24model = AutoModelForCausalLM.from_pretrained(
25 model_id,
26 quantization_config=quantization_config,
27 device_map="auto",
28 max_memory=memory_limits,
29 low_cpu_mem_usage=True
30)
31
32# Inference generation
33prompt = "Explain the core mechanics of a transformer neural network."
34messages = [
35 {"role": "system", "content": "You are a highly capable AI assistant."},
36 {"role": "user", "content": prompt}
37]
38
39text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
40model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
41
42with torch.no_grad():
43 generated_ids = model.generate(
44 **model_inputs,
45 max_new_tokens=512,
46 temperature=0.7,
47 top_p=0.9,
48 do_sample=True,
49 pad_token_id=tokenizer.eos_token_id
50 )
51
52generated_ids = [
53 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
54]
55response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
56print(response)