Improve model card and add metadata

#1
by nielsr HF Staff - opened
Files changed (1) hide show
  1. README.md +95 -2
README.md CHANGED
@@ -1,7 +1,100 @@
1
  ---
2
- license: apache-2.0
3
  base_model:
4
  - Qwen/Qwen3-4B
 
 
 
5
  ---
6
 
7
- [Flux Attention: Context-Aware Hybrid Attention for Efficient LLMs Inference](arxiv.org/abs/2604.07394)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ```