Instructions to use SafeAI-HF/ngen4ow-4b-thinking-gguf with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- llama-cpp-python
How to use SafeAI-HF/ngen4ow-4b-thinking-gguf with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="SafeAI-HF/ngen4ow-4b-thinking-gguf", filename="ngen4ow-unsafe-arch-Q4_K_M.gguf", )
llm.create_chat_completion( messages = "No input example has been defined for this model task." )
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use SafeAI-HF/ngen4ow-4b-thinking-gguf with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M # Run inference directly in the terminal: llama cli -hf SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M # Run inference directly in the terminal: llama cli -hf SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M
Use Docker
docker model run hf.co/SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M
- LM Studio
- Jan
- Ollama
How to use SafeAI-HF/ngen4ow-4b-thinking-gguf with Ollama:
ollama run hf.co/SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M
- Unsloth Studio
How to use SafeAI-HF/ngen4ow-4b-thinking-gguf with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for SafeAI-HF/ngen4ow-4b-thinking-gguf to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for SafeAI-HF/ngen4ow-4b-thinking-gguf to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for SafeAI-HF/ngen4ow-4b-thinking-gguf to start chatting
- Pi
How to use SafeAI-HF/ngen4ow-4b-thinking-gguf with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use SafeAI-HF/ngen4ow-4b-thinking-gguf with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M
Run Hermes
hermes
- Atomic Chat new
- OpenClaw new
How to use SafeAI-HF/ngen4ow-4b-thinking-gguf with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
- Docker Model Runner
How to use SafeAI-HF/ngen4ow-4b-thinking-gguf with Docker Model Runner:
docker model run hf.co/SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M
- Lemonade
How to use SafeAI-HF/ngen4ow-4b-thinking-gguf with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull SafeAI-HF/ngen4ow-4b-thinking-gguf:Q4_K_M
Run and chat with the model
lemonade run user.ngen4ow-4b-thinking-gguf-Q4_K_M
List all available models
lemonade list
- Training Report: NGen-4-OW-4B-Thinking
- 1. Executive Summary
- 2. Model Identity
- 3. Dataset
- 4. Training Infrastructure
- 5. Training Method
- 6. Run Hyperparameters
- 7. LoRA Configuration
- 8. Why These Layers Were Changed
- 9. Layers Intentionally Not Changed
- 10. Sequence Length and Long Context
- 11. Training Flow
- 12. Export and GGUF Conversion
- 13. GGUF Metadata Patch
- 14. Exported Model Metadata
- 15. Observed Training Result
- 16. Why This Training Strategy Was Reasonable
- 17. Limitations
- 18. Recommended Next Steps
- 19. Reproducibility Commands
- 20. Conclusion
- 1. Executive Summary
Training Report: NGen-4-OW-4B-Thinking
1. Executive Summary
This report documents the training, adapter merge, and GGUF export process for
TNSA/NGen-4-OW-4B-Thinking. The run used supervised fine-tuning through a
LoRA adapter on top of the Hugging Face base model, with the ArabicQA 2.1M
dataset normalized into ChatML-style training examples.
The final training run completed successfully, saved the adapter to the Modal adapter volume, merged the adapter back into the base model, converted the merged Hugging Face model to GGUF, patched the GGUF metadata where required, and produced a quantized local file:
outputs/gguf/ngen4-ow-4b-thinking-Q4_K_M.gguf
The downloaded quantized GGUF size is 2,708,803,872 bytes, approximately
2.71 GB.
2. Model Identity
The trained model is based on:
TNSA/NGen-4-OW-4B-Thinking
The model is treated as a TNSA multilingual reasoning and chat model. The fine-tuning objective was to adapt it toward a large Arabic question-answering corpus while preserving the base model's reasoning and long-context behavior.
The model was not trained from scratch. The training was parameter-efficient: the original base weights were loaded in quantized form, frozen, and adapted through trainable LoRA matrices attached to selected projection layers.
3. Dataset
The dataset used for this run was:
riotu-lab/ArabicQA_2.1M
The CLI pulled the Hugging Face dataset using the train split and normalized
it into the local JSONL file:
data/prepared/ngen41_train.jsonl
The local dataset statistics were:
| Field | Value |
|---|---|
| Source dataset | riotu-lab/ArabicQA_2.1M |
| Split | train |
| Streaming load | true |
| Rows kept | 2,141,104 |
| Rows skipped as unrecognized | 42 |
| Prepared JSONL size | about 2.29 GB |
The data preparation CLI supports common Hugging Face formats such as
messages, conversations, prompt/response, instruction/output,
question/answer, and problem/solution. Rows from ArabicQA were converted
into a standard message structure with system, user, and assistant roles.
The prepared examples were rendered during training with a ChatML-like format:
<|im_start|>system
...
<|im_end|>
<|im_start|>user
...
<|im_end|>
<|im_start|>assistant
...
<|im_end|>
This format keeps the training data aligned with the tokenizer and chat template expected by the base model.
4. Training Infrastructure
Training was run on Modal using the project app and volumes configured for this model:
| Resource | Name |
|---|---|
| Training app | ngen4-ow-4b-thinking-train |
| Data volume | ngen4-ow-4b-thinking-data |
| Adapter volume | ngen4-ow-4b-thinking-adapter |
| Export app | ngen4-ow-4b-thinking-export |
| Export volume | ngen4-ow-4b-thinking-export |
The training image was based on:
nvidia/cuda:12.8.1-devel-ubuntu22.04
Python 3.12
Key Python libraries included:
| Library | Purpose |
|---|---|
torch |
Model execution and training |
transformers |
Tokenizer, model loading, Trainer |
datasets |
JSONL training data loading |
peft |
LoRA adapter creation and merge |
bitsandbytes |
4-bit NF4 base model loading |
accelerate |
Device and training support |
huggingface_hub / hf_transfer |
HF model and dataset access |
5. Training Method
The model was trained with supervised fine-tuning using Hugging Face
Trainer. The base model was loaded in 4-bit quantized form using
BitsAndBytes:
| Setting | Value |
|---|---|
| Quantization | 4-bit |
| Quant type | nf4 |
| Compute dtype | bfloat16 |
| Double quantization | enabled |
| Attention implementation | sdpa |
| Gradient checkpointing | enabled |
| Use cache | disabled during training |
The base model was prepared for k-bit training through PEFT's
prepare_model_for_kbit_training. This is important because quantized base
models are not trained directly like full-precision models. Instead, the base
weights remain effectively frozen while LoRA adapter weights receive gradient
updates.
6. Run Hyperparameters
The final run manifest shown in the training screenshot recorded:
| Hyperparameter | Value |
|---|---|
| Base model | TNSA/NGen-4-OW-4B-Thinking |
| LoRA rank | 64 |
| LoRA alpha | 128 |
| Learning rate | 2e-6 |
| Per-device batch | 2 |
| Gradient accumulation | 4 |
| Recorded effective batch | 64 |
| Max steps | 150 |
| Training examples | 2,141,104 |
| Final logged training loss | about 2.205 |
| Training wall time in screenshot | about 1:54:58 |
The screenshot also showed the training loop completed all 150/150 steps,
then saved the final adapter and committed the output to the Modal volume.
Batch Size Note
The run manifest reports effective_batch: 64. The visible training
parameters are per_gpu_batch: 2 and grad_accum: 4. In the training script,
the manifest computes effective batch as:
per_gpu_batch * grad_accum * 8
That records an 8-way multiplier. If the run is executed on a single GPU configuration, the practical optimizer batch from the visible values is:
2 * 4 = 8 examples per optimizer step
The report keeps the manifest value because it is the value saved by the run, but this difference should be cleaned up in the training script for future runs if single-GPU and multi-GPU jobs are both supported.
7. LoRA Configuration
The model was adapted with LoRA rather than full fine-tuning. LoRA inserts small trainable low-rank matrices into selected linear layers. During training, only these adapter matrices are updated; the original base model weights remain frozen.
The run used:
| LoRA Setting | Value |
|---|---|
Rank r |
64 |
| Alpha | 128 |
| Dropout | 0.0 |
| Bias | none |
| Task type | CAUSAL_LM |
The target modules were:
q_proj
k_proj
v_proj
o_proj
gate_proj
up_proj
down_proj
These targets cover the most important transformation points in a decoder-only language model:
| Target | Function | Why it was trained |
|---|---|---|
q_proj |
Query projection in attention | Helps the model learn what to attend to for Arabic questions and instructions |
k_proj |
Key projection in attention | Adjusts how source tokens are represented for retrieval inside attention |
v_proj |
Value projection in attention | Changes what content is carried forward once attention is assigned |
o_proj |
Attention output projection | Lets the adapted attention result be integrated back into the residual stream |
gate_proj |
MLP gate projection | Controls which feed-forward features activate |
up_proj |
MLP expansion projection | Allows new task/domain features to be represented in the hidden expansion |
down_proj |
MLP compression projection | Maps adapted MLP features back into the model hidden size |
8. Why These Layers Were Changed
The selected modules balance adaptation strength and stability.
Attention projections (q_proj, k_proj, v_proj, o_proj) are responsible
for token-to-token interaction. For a QA-heavy Arabic dataset, the model must
learn patterns such as question intent, answer grounding, semantic matching,
and multilingual phrasing. Adapting attention projections helps the model
change how it routes information across the context without rewriting the
entire model.
The MLP projections (gate_proj, up_proj, down_proj) are responsible for
feature transformation after attention. These layers are where many factual,
stylistic, and reasoning transformations are expressed. Training them with
LoRA gives the model capacity to adapt answer style, domain conventions, and
Arabic QA patterns.
The combination of attention and MLP LoRA is stronger than attention-only LoRA, because the model can both attend differently and transform the attended information differently. At the same time, it is much cheaper and safer than full fine-tuning, because the base model remains frozen.
9. Layers Intentionally Not Changed
The following parts were intentionally not directly trained:
| Component | Reason |
|---|---|
| Base dense weights | Preserves base model knowledge and reduces training cost |
| Token embeddings | Avoids destabilizing the tokenizer vocabulary and rare-token behavior |
| Layer norms | Keeps normalization behavior stable during low-rank adaptation |
| Router/gating control outside LoRA targets | Reduces risk of routing collapse or expert imbalance |
| Output head | Avoids unnecessary large adapter memory and preserves base logits geometry |
The manifest records:
"router_frozen": true
Freezing router behavior is especially important for architectures with specialized routing or hybrid blocks. Router changes can create sharp behavior shifts, unstable expert use, and worse generalization if the dataset is narrow. For this run, the goal was domain adaptation rather than architectural re-routing, so the router was kept frozen.
10. Sequence Length and Long Context
The training script was configured for long context:
max_seq_length = 131072
sample_max_new = 65536
The GGUF metadata later showed:
qwen35.context_length = 262144
This means the base model and exported GGUF retain a very long context
configuration. For practical serving, the actual usable context depends on the
inference backend, GPU VRAM, quantization, KV cache settings, and request
length. The vLLM backend scaffold created separately uses a conservative
--max-model-len 32768 by default so deployment is more likely to fit on
available hardware.
11. Training Flow
The end-to-end training flow was:
- Pull the Hugging Face dataset.
- Normalize rows into chat messages.
- Write the local JSONL dataset.
- Upload the JSONL to the Modal data volume.
- Load the base model in 4-bit NF4.
- Attach LoRA adapters to selected projection layers.
- Tokenize the JSONL dataset into causal language modeling sequences.
- Train for the configured number of optimizer steps.
- Save the final adapter to
/out/final. - Commit the adapter volume.
- Merge the adapter into the base model.
- Save merged Hugging Face weights.
- Convert merged model to f16 GGUF.
- Patch GGUF block metadata if needed.
- Quantize to
Q4_K_M. - Download the final GGUF locally.
12. Export and GGUF Conversion
After training, the adapter was merged into the base model using PEFT's adapter-loading path. This was required because the base model carries PEFT or adapter-related metadata, and the older manual merge path caused a Transformers save-time adapter-state error.
The corrected export path does the following:
AutoPeftModelForCausalLM.from_pretrained(adapter_path)
merge_and_unload()
save_pretrained(merged_dir)
convert_hf_to_gguf.py --outtype f16
llama-quantize Q4_K_M
The f16 GGUF was created first:
/export/gguf/ngen4-ow-4b-thinking-f16.gguf
The quantized GGUF was then created:
/export/gguf/ngen4-ow-4b-thinking-Q4_K_M.gguf
The final local file is:
outputs/gguf/ngen4-ow-4b-thinking-Q4_K_M.gguf
13. GGUF Metadata Patch
During conversion, the GGUF converter reported:
qwen35.block_count = 33
The exporter patched this to:
qwen35.block_count = 32
This patch was necessary because the converter counted an extra prediction or auxiliary layer in a way that can confuse GGUF runtimes. The patch prevents runtime errors where the loader expects weights for a nonexistent layer.
The quantized GGUF was checked again after quantization and already had:
qwen35.block_count = 32
14. Exported Model Metadata
The export logs identified the architecture as:
Qwen3_5ForCausalLM
general.architecture = qwen35
general.size_label = 4.2B
Important GGUF metadata included:
| Field | Value |
|---|---|
| Architecture | qwen35 |
| Size label | 4.2B |
| Block count | 32 |
| Context length | 262144 |
| Embedding length | 2560 |
| Feed-forward length | 9216 |
| Attention heads | 16 |
| KV heads | 4 |
| Key length | 256 |
| Value length | 256 |
| Quantization | Q4_K_M |
| Quantized size | about 2.71 GB |
15. Observed Training Result
The training screenshot shows the run reached completion:
150/150 steps
train_loss: 2.205
epoch: 0.0005605
The very small epoch value is expected because the dataset is extremely large
relative to the number of steps. With 2,141,104 examples and only 150
training steps, the run is a short adaptation pass rather than a full epoch
over the dataset.
This is useful as a first successful adapter build because it verifies:
- Dataset normalization works.
- Modal upload works.
- The model can be loaded in 4-bit mode.
- LoRA modules can be attached and trained.
- The adapter can be saved.
- The adapter can be merged and exported.
- The GGUF can be quantized and downloaded.
It should not be treated as a fully converged training run. A longer training run, validation set, and benchmark suite are needed before making quality claims.
16. Why This Training Strategy Was Reasonable
Full fine-tuning a 4B-class model requires more memory, more time, and greater risk of catastrophic forgetting. LoRA gives a strong middle path:
- The base model remains intact.
- Training is cheaper.
- The adapter is small and easy to save.
- The adapter can be merged later for deployment.
- The target modules give enough coverage for meaningful behavior change.
The ArabicQA dataset is large and domain-specific. A short LoRA run is a good first pass for teaching the model dataset style and Arabic QA response patterns without overwriting general reasoning ability.
17. Limitations
The run has several limitations:
- The final run was only
150steps. - The dataset was large, so the model saw only a small fraction of one epoch.
- No validation metrics are recorded in the screenshot.
- The final loss alone is not enough to evaluate answer quality.
- The effective batch value in the manifest should be corrected for future single-GPU runs.
- The report does not claim benchmark improvements without evaluation.
- ArabicQA rows were normalized automatically, so spot checks should be done for formatting and answer quality.
18. Recommended Next Steps
Recommended follow-up work:
- Run a longer training job, for example
750to2000steps. - Add a held-out validation split from ArabicQA.
- Log validation loss every fixed number of steps.
- Add Arabic QA evaluation prompts.
- Add multilingual sanity prompts to ensure English and general reasoning did not regress.
- Fix the
effective_batchmanifest calculation so it reflects the actual GPU count. - Save the exact Modal app run URL and run ID in the manifest.
- Save a copy of the export manifest locally with the GGUF.
- Test the GGUF in the vLLM RAG backend and with a direct local runtime.
19. Reproducibility Commands
The dataset preparation and training command used for this family of run was:
python scripts/ngen_thinking_cli.py train-hf riotu-lab/ArabicQA_2.1M --split train --max-steps 750
The screenshoted completed run itself records:
max_steps = 150
The GGUF export command was:
python scripts/ngen_thinking_cli.py export --checkpoint final --quant Q4_K_M --download
The final GGUF file:
C:\Users\NACHIKETH\Desktop\NGen-4.1\NGen-4-OW-4B-Thinking\outputs\gguf\ngen4-ow-4b-thinking-Q4_K_M.gguf
20. Conclusion
The training pipeline successfully adapted TNSA/NGen-4-OW-4B-Thinking with a
LoRA adapter over selected attention and MLP projection layers, using
riotu-lab/ArabicQA_2.1M as the training corpus. The adapter was saved,
merged, converted to GGUF, patched for correct Qwen block metadata, quantized
to Q4_K_M, and downloaded locally.
The most important architectural decision was to update projection layers instead of the full model. This gave the run enough flexibility to learn Arabic QA behavior while keeping training cost and regression risk low. The router and core base weights remained frozen to preserve stability.
This should be considered a successful first training and export pass. The next step is evaluation: compare the base model and the tuned GGUF on Arabic QA, general chat, reasoning, and RAG tasks before positioning it as a production model.
- Downloads last month
- 18
4-bit