Instructions to use ZengXiangyu/Llama-2-7b-HiCI-100k with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use ZengXiangyu/Llama-2-7b-HiCI-100k with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("/mnt/bn/strategy-mllm-train/user/xuqi/repos/zxy/llm-memory/data1/pretrained-models/llama-7b-hf/models--meta-llama--Llama-2-7b-hf/snapshots/01c7f73d771dfac7d292323805ebc428287df4f9") model = PeftModel.from_pretrained(base_model, "ZengXiangyu/Llama-2-7b-HiCI-100k") - Notebooks
- Google Colab
- Kaggle
Llama-2-7b-HiCI-100k
π₯ A Llama-2-7B with Hierarchical Context Integration (HiCI)
π― Key Highlights
- Extended Context: 8,192 tokens (4Γ base Llama-2)
- Novel Architecture: Hierarchical Context Integration (HiCI)
- 512M Trainable Parameters: Including 380M for HiCI modules
- Based on LongLoRA: Efficient training with shifted sparse attention
π Differences from Standard LongLoRA
| Component | Standard LongLoRA | This Model (HiCI) |
|---|---|---|
| LoRA Adapters | q,k,v,o projections | β Same (27MB) |
| Embeddings | Token embeddings | β Same (500MB) |
| Normalization | LayerNorm weights | β Same (1MB) |
| π₯ Local Construction | β Not included | β 269M params (1GB) |
| π₯ Global Integration | β Not included | β 111M params (424MB) |
| Total Size | ~1.1 GB | ~2 GB |
Trade-off: 2Γ larger checkpoint for hierarchical context conditioning.
Architecture Details
HiCI Module Breakdown
Technical Overview:
Standard self-attention has $\mathcal{O}(T^2)$ complexity. HiCI uses segmented attention with structured context conditioning:
- Local Construction: Cross-attention with $M$ learnable query slots extracts compact local representations $L_i \in \mathbb{R}^{M imes d}$ from each segment
- Global Integration: Local representations are aggregated into shared global context $G \in \mathbb{R}^{K imes d}$ via multi-view statistical pooling
- Top-down Broadcast: Global context $G$ and local abstraction $L_i$ are prepended to each segment's key-value sequence
This achieves $\mathcal{O}(T \cdot S)$ complexity while maintaining cross-segment information flow.
File Structure
adapter_model.bin (27 MB)
βββ LoRA Adapters: 13.9M parameters
βββ Target: q_proj, k_proj, v_proj, o_proj
trainable_params.bin (2 GB)
βββ Local Construction Modules: 269M parameters (1.0 GB) π₯
βββ Global Integration Modules: 111M parameters (424 MB) π₯
βββ Embeddings: 131M parameters (500 MB)
βββ Normalization: 0.27M parameters (1 MB)
π» Usage
Installation
pip install transformers peft torch
Load Model
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch
# Load base model
base_model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Llama-2-7b-hf",
torch_dtype=torch.bfloat16,
device_map="auto"
)
# Load HICI adapter
model = PeftModel.from_pretrained(
base_model,
"ZengXiangyu/Llama-2-7b-HiCI-100k"
)
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained("ZengXiangyu/Llama-2-7b-HiCI-100k")
# Generate
prompt = "Your long context (up to 16K tokens)..."
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
β οΈ Important Note
This model uses HiCI (Hierarchical Context Integration) modules for enhanced long-context capabilities. The implementation code will be available on GitHub. For now, you can load and use the model with standard PEFT interface as shown above.
## License
Llama 2 Community License
## π Acknowledgements
- Based on [Llama-2-7B](https://huggingface.co/meta-llama/Llama-2-7b-hf) by Meta AI
- Training methodology from [LongLoRA](https://github.com/dvlab-research/LongLoRA)
- HiCI architecture: Hierarchical Context Integration with segmented attention
- Downloads last month
- 13
Inference Providers NEW
This model isn't deployed by any Inference Provider. π Ask for provider support
Model tree for ZengXiangyu/Llama-2-7b-HiCI-100k
Base model
meta-llama/Llama-2-7b-hf