CoolFace
Modelpublic

ZengXiangyu/Llama-2-7b-HiCI-100k

sourceHugging Facellama2updated 8mo agoView on Hugging Face
0likes11downloads
Model Card

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

ComponentStandard LongLoRAThis Model (HiCI)
LoRA Adaptersq,k,v,o projectionsโœ… Same (27MB)
EmbeddingsToken embeddingsโœ… Same (500MB)
NormalizationLayerNorm 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:

  1. 1.Local Construction: Cross-attention with $M$ learnable query slots extracts compact local representations $L_i \in \mathbb{R}^{M imes d}$ from each segment
  2. 2.Global Integration: Local representations are aggregated into shared global context $G \in \mathbb{R}^{K imes d}$ via multi-view statistical pooling
  3. 3.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

bash
pip install transformers peft torch

Load Model

python
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