D-Spark-4B
[!NOTE] Korrektur / Correction (2026-11-23)
DE: Die Gewichte in diesem Repo sind Byte für Byte identisch mit XHToken/Spark-X2.5-4B (SHA-256 der Safetensors-Dateien verglichen). Geändert wurden nur Konfiguration, Chat-Template bzw. Doku. Aussagen über zusätzliches Training oder bessere Benchmark-Werte beziehen sich daher nicht auf andere Gewichte als das Original. Gegenüber dem Original ist nur das Muster der Sliding-/Full-Attention-Layer geändert (4:1 statt 3:1). Die Intermediate Size ist 10240, nicht 9216 (
config.jsonkorrigiert, sonst passten die Gewichte nicht).EN: The weights in this repo are byte-identical to XHToken/Spark-X2.5-4B (SHA-256 of the safetensors files compared). Only configuration, chat template and/or documentation were changed. Claims about additional training or improved benchmark scores therefore do not refer to weights that differ from the original. Compared with the original only the sliding/full attention layer pattern is changed (4:1 instead of 3:1). The intermediate size is 10240, not 9216 (
config.jsonfixed; the weights did not match before).
D-Spark-4B is a compact, general-purpose language model optimized for efficient inference on small devices while preserving strong performance across conversation, writing, translation, reasoning, coding, tool use, and agentic workflows. It natively supports context windows of up to 1M tokens and more than 200 languages.
Technical Highlights
- Efficient Hybrid Architecture: Combines sliding-window attention (majority of layers) with sparse full-attention layers. This design significantly reduces KV-cache memory and compute on resource-constrained hardware while retaining long-context capability.
- Optimized for Edge & On-Device: Reduced intermediate size and a higher ratio of sliding-window layers improve TTFT, throughput, and memory footprint compared with similar 4B-class models.
- Strong Coding & Agent Capabilities: Compatible with popular agent frameworks. Delivers competitive results on everyday coding, agentic workflows, reasoning, and instruction-following tasks.
- Broad Compatibility: Supports NVIDIA, Apple Silicon (MLX), CPU, and other platforms. Works with vLLM, SGLang, llama.cpp, Ollama, LM Studio, and can be fine-tuned with Llama-Factory.
Model Overview
| Parameter | Value |
|---|---|
| Parameters | ~4.1 B |
| Hidden size | 2560 |
| Intermediate size | 10240 |
| Layers | 36 |
| Attention heads | 16 (KV: 4) |
| Head dim | 256 |
| Sliding window | 512 |
| Max context | 1 048 576 |
| Vocab size | 131 072 |
| Precision | bfloat16 |
Layer pattern (higher sliding ratio for efficiency): 4 × sliding → 1 × full (repeated), ending with sliding.
Recommended Sampling
{
"temperature": 1.0,
"top_p": 0.95,
"top_k": -1,
"repetition_penalty": 1.0
}
Thinking mode is enabled by default via the chat template. Disable with "chat_template_kwargs": {"enable_thinking": false}.
Quickstart (Transformers)
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_id = "OceanLabs/Ocean-1-4B-DSpark"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True,
)
messages = [{"role": "user", "content": "What is the capital of Anhui Province?"}]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(model.device)
outputs = model.generate(inputs, max_new_tokens=256)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Intended use / Einsatzzweck
- EN: General assistant, writing, coding, reasoning and agentic / tool-use experiments; research and prototyping.
- DE: Allgemeiner Assistent, Schreiben, Programmieren, Reasoning sowie Agenten- und Tool-Use-Experimente; Forschung und Prototypen.
Limitations / Einschränkungen
- EN: Can hallucinate or produce wrong answers and code; verify outputs. No own benchmark runs for this repo; see the base model's card for measured scores. Requires
trust_remote_code=True; review the included Python files before running. Very long contexts need a lot of GPU memory. Inherits limitations and biases of the base model. - DE: Kann halluzinieren oder falsche Antworten und fehlerhaften Code liefern; Ausgaben prüfen. Für dieses Repo wurden keine eigenen Benchmarks gemessen; Werte stehen in der Karte des Basismodells. Benötigt
trust_remote_code=True; die mitgelieferten Python-Dateien vor dem Ausführen prüfen. Sehr lange Kontexte brauchen viel GPU-Speicher. Übernimmt Einschränkungen und Verzerrungen des Basismodells.
License
Apache 2.0
Citation
@misc{dspark,
title = {D-Spark-4B: Efficient On-Device Language Model},
author = {D-Spark Team},
year = {2026}
}