Downloads · 30 days
0
moelanoby/ALM-Qwen-0.5B-testing
ALM-Qwen-0.5B-testing is a machine learning model from moelanoby. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers.
This repository contains an Attention-Linked Memory augmented Qwen model (ALM-Qwen).
Downloads · 30 days
0
Access
Public
Updated May 27, 2025
Repo size
1 GB
Likes
1
Public
Click a slice to open those files.
.safetensors988 MB · 98%
From the Hugging Face model README
This repository contains an Attention-Linked Memory augmented Qwen model (ALM-Qwen).
ALM.py)alm_qwen.py)alm_layer_state_dict.pth: Trained weights for the ALM layer.alm_qwen_hf_config.json: Configuration for the ALMQwenModel_HF, including ALM parameters and paths to the Qwen components.qwen_generator/: Contains the saved Hugging Face Qwen model and tokenizer.Prerequisites:
pip install torch transformers huggingface_hub sentencepiece accelerate
# Add other dependencies if any, e.g., bitsandbytes for quantization
Clone the repository (or download files manually):
git lfs install # if large files are used, though typically not for these components directly
git clone https://huggingface.co/moelanoby/ALM-Qwen-0.5B-testing
cd ALM-Qwen-0.5B-testing
Load the model in Python:
from alm_qwen import ALMQwenModel_HF # Make sure alm_qwen_hf.py and ALM.py are in your PYTHONPATH
import torch
# Desired device
device = "cuda" if torch.cuda.is_available() else "cpu"
# Path to the directory where you cloned/downloaded the model
model_directory = "." # Or the specific path if you are running from outside the cloned repo
# Load the model
loaded_model = ALMQwenModel_HF.load_model(model_directory, device=device)
print("ALM-Qwen model loaded successfully!")
# --- Prepare Dummy Input Data (similar to the example in alm_qwen_hf.py) ---
# batch_size = 1
# alm_query_dim = loaded_model.alm_config['query_dim']
# alm_memory_dim = loaded_model.alm_config['memory_dim']
# num_kb_buckets = 3 # Example
# max_kb_items_per_bucket = 5 # Example
# query_texts = ["What is the capital of France?"]
# query_embeddings_for_alm = torch.randn(batch_size, alm_query_dim)
# memory_item_embeddings = torch.randn(batch_size, num_kb_buckets, max_kb_items_per_bucket, alm_memory_dim)
# memory_text_items = [[["Paris is the capital of France." for _ in range(max_kb_items_per_bucket)] for _ in range(num_kb_buckets)] for _ in range(batch_size)]
# memory_mask = torch.ones(batch_size, num_kb_buckets, max_kb_items_per_bucket, dtype=torch.bool)
# memory_mask[:, :, -1] = False # Example mask
# # Run inference
# generated_answers, _, _ = loaded_model(
# query_texts,
# query_embeddings_for_alm,
# memory_item_embeddings,
# memory_text_items,
# memory_mask
# )
# print(f"Query: {query_texts[0]}")
# print(f"Answer: {generated_answers[0]}")
The ALM layer (alm_layer_state_dict.pth) might have been trained. The Qwen model inside qwen_generator/ is typically a pre-trained model from Hugging Face, possibly fine-tuned.
load_model method in alm_qwen_hf.py handles the reconstruction of the composite model.