Instructions to use kiel2/kiel-2-codex with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use kiel2/kiel-2-codex with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("kiel2/kiel-2-codex") model = PeftModel.from_pretrained(base_model, "kiel2/kiel-2-codex") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Desktop
Update README.md
Browse files
README.md
CHANGED
|
@@ -3,10 +3,11 @@ license: mit
|
|
| 3 |
language:
|
| 4 |
- en
|
| 5 |
tags:
|
|
|
|
| 6 |
- vision-language
|
| 7 |
- safetensors
|
| 8 |
-
- quantization
|
| 9 |
- 4-bit
|
|
|
|
| 10 |
- bitsandbytes
|
| 11 |
- multimodal
|
| 12 |
- kielgen-codex
|
|
@@ -15,88 +16,93 @@ tags:
|
|
| 15 |
base_model: Qwen/Qwen3-VL-4B
|
| 16 |
---
|
| 17 |
|
| 18 |
-
# KielGen-Codex
|
| 19 |
|
| 20 |
-
`KielGen-Codex` is a fine-tuned multimodal vision-language model (`Qwen3VLForConditionalGeneration`) optimized for advanced visual understanding, spatial perception, and text generation pipelines. This repository contains
|
| 21 |
|
| 22 |
---
|
| 23 |
|
| 24 |
## 📁 Model Overview & Files
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
| Filename | Format / Quantization | Description |
|
| 29 |
| :--- | :--- | :--- |
|
| 30 |
-
| `KielGen-Codex_4bit.safetensors` | SafeTensors (4-bit `nf4`) | Optimized 4-bit compressed unified weights
|
| 31 |
-
| `KielGen-Codex_16-bit.safetensors` | SafeTensors (FP16) | Full-precision unquantized unified weights (
|
| 32 |
-
| `config.json` / Processor files | FP16 / Config | Native model configurations and processor files required for
|
| 33 |
|
|
|
|
| 34 |
|
| 35 |
## 🛠️ Model Architecture & Technical Specs
|
| 36 |
|
| 37 |
* **Base Architecture**: Qwen3-VL (`Qwen3VLForConditionalGeneration`)
|
| 38 |
-
* **Quantization Type**: 4-bit Normalized Float (`nf4`) with double quantization via `bitsandbytes`
|
| 39 |
* **Supported Modalities**: Unified Text & Vision (Image Understanding + Text Generation)
|
|
|
|
| 40 |
|
| 41 |
---
|
| 42 |
|
| 43 |
## 🚀 Quickstart Usage
|
| 44 |
|
| 45 |
-
You can load and run this model directly in Python using Hugging Face `transformers` and `bitsandbytes`.
|
| 46 |
-
|
| 47 |
-
### Prerequisites
|
| 48 |
Make sure you have the required libraries installed:
|
| 49 |
```bash
|
| 50 |
pip install -U transformers accelerate bitsandbytes torchvision
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
Python
|
| 53 |
-
Here is how to load the model in 4-bit and perform both text generation and image understanding:
|
| 54 |
-
|
| 55 |
-
Python
|
| 56 |
import torch
|
| 57 |
from transformers import Qwen3VLForConditionalGeneration, AutoProcessor, BitsAndBytesConfig
|
| 58 |
-
|
| 59 |
-
# 1. Configure 4-bit quantization settings
|
| 60 |
bnb_config = BitsAndBytesConfig(
|
| 61 |
load_in_4bit=True,
|
| 62 |
bnb_4bit_compute_dtype=torch.float16,
|
| 63 |
bnb_4bit_quant_type="nf4",
|
| 64 |
bnb_4bit_use_double_quant=True
|
| 65 |
)
|
| 66 |
-
```
|
| 67 |
|
| 68 |
-
# 2. Load the
|
| 69 |
-
```
|
| 70 |
repo_id = "kiel2/KielGen-Codex"
|
|
|
|
| 71 |
|
| 72 |
print("Loading KielGen-Codex in 4-bit...")
|
| 73 |
model = Qwen3VLForConditionalGeneration.from_pretrained(
|
| 74 |
repo_id,
|
|
|
|
| 75 |
quantization_config=bnb_config,
|
| 76 |
device_map="auto",
|
| 77 |
trust_remote_code=True
|
| 78 |
)
|
| 79 |
|
| 80 |
-
processor = AutoProcessor.from_pretrained(repo_id, trust_remote_code=True)
|
| 81 |
-
|
| 82 |
-
# ==========================================
|
| 83 |
-
# TEST 1: Pure Text Generation
|
| 84 |
-
# ==========================================
|
| 85 |
-
text_messages = [
|
| 86 |
-
{"role": "system", "content": "You are a helpful AI engineering assistant."},
|
| 87 |
-
{"role": "user", "content": "Write a python function to reverse a string."}
|
| 88 |
-
]
|
| 89 |
-
|
| 90 |
-
text_input = processor.apply_chat_template(
|
| 91 |
-
text_messages,
|
| 92 |
-
tokenize=True,
|
| 93 |
-
add_generation_prompt=True,
|
| 94 |
-
return_tensors="pt"
|
| 95 |
-
).to("cuda")
|
| 96 |
-
|
| 97 |
-
generated_ids = model.generate(**text_input, max_new_tokens=150)
|
| 98 |
-
print("--- Text Generation Output ---")
|
| 99 |
-
print(processor.batch_decode(generated_ids, skip_special_tokens=True)[0])
|
| 100 |
```
|
| 101 |
-
|
| 102 |
-
The
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
language:
|
| 4 |
- en
|
| 5 |
tags:
|
| 6 |
+
- qwen3-vl
|
| 7 |
- vision-language
|
| 8 |
- safetensors
|
|
|
|
| 9 |
- 4-bit
|
| 10 |
+
- 16-bit
|
| 11 |
- bitsandbytes
|
| 12 |
- multimodal
|
| 13 |
- kielgen-codex
|
|
|
|
| 16 |
base_model: Qwen/Qwen3-VL-4B
|
| 17 |
---
|
| 18 |
|
| 19 |
+
# KielGen-Codex (Unified Multimodal)
|
| 20 |
|
| 21 |
+
`KielGen-Codex` is a fine-tuned multimodal vision-language model (`Qwen3VLForConditionalGeneration`) optimized for advanced visual understanding, spatial perception, and text generation pipelines. This repository contains both full-precision 16-bit and compressed 4-bit SafeTensors weights, natively integrating text generation and image encoding into a single package.
|
| 22 |
|
| 23 |
---
|
| 24 |
|
| 25 |
## 📁 Model Overview & Files
|
| 26 |
|
| 27 |
+
| Filename / Path | Format / Precision | Description |
|
|
|
|
|
|
|
| 28 |
| :--- | :--- | :--- |
|
| 29 |
+
| `4bit/KielGen-Codex_4bit.safetensors` | SafeTensors (4-bit `nf4`) | Optimized 4-bit compressed unified weights via `bitsandbytes` (~2.4 GB VRAM footprint). Ideal for consumer GPUs. |
|
| 30 |
+
| `16bit/KielGen-Codex_16-bit.safetensors` | SafeTensors (FP16) | Full-precision unquantized unified weights (~7.7 GB VRAM footprint) maintaining maximum native accuracy. |
|
| 31 |
+
| `config.json` / Processor files | FP16 / Config | Native model configurations and vision processor files required for execution. |
|
| 32 |
|
| 33 |
+
---
|
| 34 |
|
| 35 |
## 🛠️ Model Architecture & Technical Specs
|
| 36 |
|
| 37 |
* **Base Architecture**: Qwen3-VL (`Qwen3VLForConditionalGeneration`)
|
|
|
|
| 38 |
* **Supported Modalities**: Unified Text & Vision (Image Understanding + Text Generation)
|
| 39 |
+
* **Framework**: Hugging Face `transformers` & `bitsandbytes`
|
| 40 |
|
| 41 |
---
|
| 42 |
|
| 43 |
## 🚀 Quickstart Usage
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
Make sure you have the required libraries installed:
|
| 46 |
```bash
|
| 47 |
pip install -U transformers accelerate bitsandbytes torchvision
|
| 48 |
+
```
|
| 49 |
+
Option A: Loading the 4-Bit Version (Low VRAM / Edge Deployments)
|
| 50 |
+
The 4-bit configuration uses bitsandbytes quantization to compress both the text backbone and vision tower simultaneously into memory:
|
| 51 |
|
| 52 |
+
```Python
|
|
|
|
|
|
|
|
|
|
| 53 |
import torch
|
| 54 |
from transformers import Qwen3VLForConditionalGeneration, AutoProcessor, BitsAndBytesConfig
|
| 55 |
+
```
|
| 56 |
+
# 1. Configure 4-bit quantization settings
|
| 57 |
bnb_config = BitsAndBytesConfig(
|
| 58 |
load_in_4bit=True,
|
| 59 |
bnb_4bit_compute_dtype=torch.float16,
|
| 60 |
bnb_4bit_quant_type="nf4",
|
| 61 |
bnb_4bit_use_double_quant=True
|
| 62 |
)
|
|
|
|
| 63 |
|
| 64 |
+
# 2. Load the 4-bit weights from your repository subfolder
|
| 65 |
+
```
|
| 66 |
repo_id = "kiel2/KielGen-Codex"
|
| 67 |
+
subfolder = "4bit" # Adjust if stored in a custom directory
|
| 68 |
|
| 69 |
print("Loading KielGen-Codex in 4-bit...")
|
| 70 |
model = Qwen3VLForConditionalGeneration.from_pretrained(
|
| 71 |
repo_id,
|
| 72 |
+
subfolder=subfolder,
|
| 73 |
quantization_config=bnb_config,
|
| 74 |
device_map="auto",
|
| 75 |
trust_remote_code=True
|
| 76 |
)
|
| 77 |
|
| 78 |
+
processor = AutoProcessor.from_pretrained(repo_id, subfolder=subfolder, trust_remote_code=True)
|
| 79 |
+
print("-> 4-bit Model loaded successfully!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
```
|
| 81 |
+
Option B: Loading the 16-Bit Version (Full Precision / Maximum Accuracy)
|
| 82 |
+
The 16-bit configuration loads the original unquantized weights directly in FP16 precision. This requires more VRAM (~8 GB+), but preserves absolute native accuracy for complex reasoning:
|
| 83 |
+
|
| 84 |
+
Python
|
| 85 |
+
import torch
|
| 86 |
+
from transformers import Qwen3VLForConditionalGeneration, AutoProcessor
|
| 87 |
+
|
| 88 |
+
# 1. Load the full-precision 16-bit weights from your repository subfolder
|
| 89 |
+
repo_id = "kiel2/KielGen-Codex"
|
| 90 |
+
subfolder = "16bit" # Adjust if stored in a custom directory
|
| 91 |
+
|
| 92 |
+
print("Loading KielGen-Codex in 16-bit (FP16)...")
|
| 93 |
+
model = Qwen3VLForConditionalGeneration.from_pretrained(
|
| 94 |
+
repo_id,
|
| 95 |
+
subfolder=subfolder,
|
| 96 |
+
torch_dtype=torch.float16, # Casts weights directly to FP16
|
| 97 |
+
device_map="auto",
|
| 98 |
+
trust_remote_code=True
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
processor = AutoProcessor.from_pretrained(repo_id, subfolder=subfolder, trust_remote_code=True)
|
| 102 |
+
print("-> 16-bit Model loaded successfully!")
|
| 103 |
+
|
| 104 |
+
### 💡 Explanation of the Code Differences
|
| 105 |
+
|
| 106 |
+
* **`BitsAndBytesConfig` (Option A)**: This object tells Hugging Face to intercept the model loading process and compress the weights down to 4-bit `nf4` format on-the-fly, drastically reducing memory requirements for consumer GPUs.
|
| 107 |
+
* **`torch_dtype=torch.float16` (Option B)**: This instructs PyTorch to map the tensors directly into native half-precision floating-point format without any compression overhead, leveraging your GPU's tensor cores at full 16-bit fidelity.
|
| 108 |
+
* **`subfolder` Parameter**: By organizing the repository into clean subfolders (`4bit/` and `16bit/`), you can seamlessly target whichever file variant you need without running into filename conflicts or downloading unnecessary weights.
|