Instructions to use QQTang1223/full_streaming_Qwen3-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use QQTang1223/full_streaming_Qwen3-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="QQTang1223/full_streaming_Qwen3-4B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("QQTang1223/full_streaming_Qwen3-4B") model = AutoModelForCausalLM.from_pretrained("QQTang1223/full_streaming_Qwen3-4B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use QQTang1223/full_streaming_Qwen3-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "QQTang1223/full_streaming_Qwen3-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "QQTang1223/full_streaming_Qwen3-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/QQTang1223/full_streaming_Qwen3-4B
- SGLang
How to use QQTang1223/full_streaming_Qwen3-4B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "QQTang1223/full_streaming_Qwen3-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "QQTang1223/full_streaming_Qwen3-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "QQTang1223/full_streaming_Qwen3-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "QQTang1223/full_streaming_Qwen3-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use QQTang1223/full_streaming_Qwen3-4B with Docker Model Runner:
docker model run hf.co/QQTang1223/full_streaming_Qwen3-4B
Improve model card and add metadata
#1
by nielsr HF Staff - opened
README.md
CHANGED
|
@@ -1,7 +1,100 @@
|
|
| 1 |
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
base_model:
|
| 4 |
- Qwen/Qwen3-4B
|
|
|
|
|
|
|
|
|
|
| 5 |
---
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
|
|
|
| 2 |
base_model:
|
| 3 |
- Qwen/Qwen3-4B
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
library_name: transformers
|
| 6 |
+
pipeline_tag: text-generation
|
| 7 |
---
|
| 8 |
|
| 9 |
+
# Flux Attention: Context-Aware Hybrid Attention for Efficient LLMs Inference
|
| 10 |
+
|
| 11 |
+
[Flux Attention](https://qqtang-code.github.io/FluxAttention-Project-Page/) is a context-aware framework that dynamically optimizes attention computation at the layer level. By integrating a lightweight Layer Router into frozen pretrained LLMs, it adaptively routes each layer to Full Attention (FA) or Sparse Attention (SA) based on the input context. This approach preserves high-fidelity information retrieval while ensuring substantial wall-clock speedups on long-context tasks.
|
| 12 |
+
|
| 13 |
+
- **Paper:** [Flux Attention: Context-Aware Hybrid Attention for Efficient LLMs Inference](https://huggingface.co/papers/2604.07394)
|
| 14 |
+
- **Repository:** [https://github.com/qqtang-code/FluxAttention](https://github.com/qqtang-code/FluxAttention)
|
| 15 |
+
- **Project Page:** [https://qqtang-code.github.io/FluxAttention-Project-Page/](https://qqtang-code.github.io/FluxAttention-Project-Page/)
|
| 16 |
+
|
| 17 |
+
## Quick Start (Inference)
|
| 18 |
+
|
| 19 |
+
The following example demonstrates how to use Flux Attention for text generation. Note that this requires the `fluxattn` package and `Block-Sparse-Attention` to be installed as described in the [official repository](https://github.com/qqtang-code/FluxAttention).
|
| 20 |
+
|
| 21 |
+
```python
|
| 22 |
+
import torch
|
| 23 |
+
import json
|
| 24 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 25 |
+
|
| 26 |
+
def load_sparse_model(model_path):
|
| 27 |
+
"""
|
| 28 |
+
Dynamically loads the correct sparse architecture based on config.
|
| 29 |
+
"""
|
| 30 |
+
config_path = f"{model_path}/config.json"
|
| 31 |
+
with open(config_path, "r") as f:
|
| 32 |
+
config_data = json.load(f)
|
| 33 |
+
|
| 34 |
+
arch = config_data.get("architectures", [])
|
| 35 |
+
if not arch:
|
| 36 |
+
raise ValueError("No architecture found in config.json")
|
| 37 |
+
|
| 38 |
+
arch_name = arch[0]
|
| 39 |
+
print(f"🚀 Detected architecture: {arch_name}")
|
| 40 |
+
|
| 41 |
+
# Register custom architectures
|
| 42 |
+
if "PawLlama" in arch_name:
|
| 43 |
+
from fluxattn.training.eval.modeling_flash_llama import (
|
| 44 |
+
PawLlamaForCausalLM, PawLlamaConfig
|
| 45 |
+
)
|
| 46 |
+
AutoModelForCausalLM.register(PawLlamaConfig, PawLlamaForCausalLM)
|
| 47 |
+
model_cls = PawLlamaForCausalLM
|
| 48 |
+
|
| 49 |
+
elif "PawQwen" in arch_name:
|
| 50 |
+
from fluxattn.training.eval.modeling_flash_qwen import (
|
| 51 |
+
PawQwen3ForCausalLM, PawQwen3Config
|
| 52 |
+
)
|
| 53 |
+
AutoModelForCausalLM.register(PawQwen3Config, PawQwen3ForCausalLM)
|
| 54 |
+
model_cls = PawQwen3ForCausalLM
|
| 55 |
+
else:
|
| 56 |
+
raise ValueError(f"Unsupported architecture: {arch_name}")
|
| 57 |
+
|
| 58 |
+
# Load model
|
| 59 |
+
model = model_cls.from_pretrained(
|
| 60 |
+
model_path,
|
| 61 |
+
torch_dtype=torch.bfloat16,
|
| 62 |
+
device_map="auto",
|
| 63 |
+
trust_remote_code=True,
|
| 64 |
+
)
|
| 65 |
+
return model
|
| 66 |
+
|
| 67 |
+
# --- Execution ---
|
| 68 |
+
model_path = "QQTang1223/Flux-Attention-Qwen3-4B" # <--- Replace with your checkpoint path
|
| 69 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
| 70 |
+
|
| 71 |
+
print("Loading Flux Attention Model...")
|
| 72 |
+
model = load_sparse_model(model_path)
|
| 73 |
+
model.eval()
|
| 74 |
+
|
| 75 |
+
# Generate
|
| 76 |
+
input_text = "Explain quantum mechanics in one sentence."
|
| 77 |
+
inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
|
| 78 |
+
|
| 79 |
+
print("Generating...")
|
| 80 |
+
outputs = model.generate(**inputs, max_new_tokens=100)
|
| 81 |
+
print("
|
| 82 |
+
Output:
|
| 83 |
+
" + tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
## Citation
|
| 87 |
+
|
| 88 |
+
If you find this project useful in your research, please consider citing:
|
| 89 |
+
|
| 90 |
+
```bibtex
|
| 91 |
+
@misc{qiu2026fluxattentioncontextawarehybrid,
|
| 92 |
+
title={Flux Attention: Context-Aware Hybrid Attention for Efficient LLMs Inference},
|
| 93 |
+
author={Quantong Qiu and Zhiyi Hong and Yi Yang and Haitian Wang and Kebin Liu and Qingqing Dang and Juntao Li and Min Zhang},
|
| 94 |
+
year={2026},
|
| 95 |
+
eprint={2604.07394},
|
| 96 |
+
archivePrefix={arXiv},
|
| 97 |
+
primaryClass={cs.LG},
|
| 98 |
+
url={https://arxiv.org/abs/2604.07394},
|
| 99 |
+
}
|
| 100 |
+
```
|