Instructions to use AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit") model = AutoModelForCausalLM.from_pretrained("AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit") 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit
- SGLang
How to use AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit 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 "AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit" \ --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": "AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit", "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 "AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit" \ --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": "AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio new
How to use AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit", max_seq_length=2048, ) - Docker Model Runner
How to use AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit with Docker Model Runner:
docker model run hf.co/AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit
AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit
This repository contains code and documentation for the Llama 3.2 1B variant of our dynamic topic modeling series, based on the RedPajama dataset subset we created for dynamic topic-modeling. Link to dataset: AmanPriyanshu/Dynamic-Topic-RedPajama-Data-1T-100k-SubSample-max-1k-tokens
Model Comparisons
| Model | Parameters | Loss |
|---|---|---|
| Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit | 1B | 2.3959 |
Model Overview
- Base Model: Unsloth/Llama-3.2-1B-bnb-4bit
- Fine-tuned Version: AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit
- Task: Hierarchical Topic Generation
- Training Data: 100k samples from RedPajama-1T
Dataset Details
The model was trained on a carefully curated subset of the RedPajama-1T dataset:
- 100,000 documents
- Maximum 1,024 tokens per document
- Three-level hierarchical topic annotations
- Original sources include: CommonCrawl, C4, GitHub, Books, ArXiv, Wikipedia, StackExchange
Model Architecture & Training
Key Configuration:
- Sequence Length: 2048 tokens
- LoRA Parameters:
- Rank: 16
- Alpha: 16
- Target Modules: q_proj, k_proj, v_proj, up_proj, down_proj, o_proj, gate_proj
- RSLoRA enabled
Training Parameters:
- Batch Size: 4
- Gradient Accumulation Steps: 2
- Learning Rate: 3e-4
- Epochs: 1
- Optimizer: AdamW 8-bit
- Weight Decay: 0.01
- Warmup Steps: 10
Usage
Check out the Colab Notebook: https://colab.research.google.com/drive/173dKPjMmFZcbMoyHHdG5pOWH5qRyhcyW?usp=sharing
Installation
pip install unsloth transformers torch
Inference Code
from unsloth import FastLanguageModel
import torch
from transformers import TextStreamer
class LlamaInference:
def __init__(self, model_path: str, device: str = "cuda"):
self.device = device
self.model, self.tokenizer = FastLanguageModel.from_pretrained(
model_name=model_path,
max_seq_length=2048,
load_in_4bit=True,
dtype=None,
)
self.model = FastLanguageModel.for_inference(self.model)
self.model.eval()
def generate_response(
self,
prompt: str,
max_new_tokens: int = 512,
temperature: float = 0.7,
top_p: float = 0.9,
stream: bool = True
) -> str:
messages = [{"from": "human", "value": prompt}]
inputs = self.tokenizer.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_tensors="pt"
).to(self.device)
streamer = TextStreamer(self.tokenizer) if stream else None
with torch.no_grad():
outputs = self.model.generate(
input_ids=inputs,
max_new_tokens=max_new_tokens,
temperature=temperature,
top_p=top_p,
streamer=streamer,
use_cache=True,
pad_token_id=self.tokenizer.pad_token_id,
eos_token_id=self.tokenizer.eos_token_id,
)
if not stream:
response = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
response = response.split("assistant\n")[-1].strip()
return response
Example Usage
model_path = "AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit"
inferencer = LlamaInference(model_path)
response = inferencer.generate_response("Your text here", stream=False)
Output Format
The model generates hierarchical topics in the format:
Domain > High-Level Topic > Specific Topic
Example:
Input: """Machine learning (ML) is a field of study in artificial intelligence concerned with the development and study of statistical algorithms that can learn from data and generalize to unseen data, and thus perform tasks without explicit instructions.[1] Advances in the field of deep learning have allowed neural networks to surpass many previous approaches in performance.[2] ML finds application in many fields, including natural language processing, computer vision, speech recognition, email filtering, agriculture, and medicine.[3][4] The application of ML to business problems is known as predictive analytics. Statistics and mathematical optimization (mathematical programming) methods comprise the foundations of machine learning. Data mining is a related field of study, focusing on exploratory data analysis (EDA) via unsupervised learning.[6][7] From a theoretical viewpoint, probably approximately correct (PAC) learning provides a framework for describing machine learning."""
Output: "Machine Learning > Definition > Overview"
License
This project is released under LLaMA-3.2 License.
Citation
If you use this model or dataset in your research, please cite:
@misc{dynamic-topic-llama,
author = {Aman Priyanshu},
title = {Dynamic Topic Modeling Llama 3.2 1B},
year = {2024},
publisher = {HuggingFace}
}
- Downloads last month
- 44
Model tree for AmanPriyanshu/Dynamic-Topic-Modeling-Llama-3.2-1B-bnb-4bit
Base model
meta-llama/Llama-3.2-1B