Views
No views yet
| Branch | Bits | Description |
|---|---|---|
| 8_0 | 8.0 | Maximum quality that ExLlamaV2 can produce, near unquantized performance. |
| 6_5 | 6.5 | Very similar to 8.0, good tradeoff of size vs performance, recommended. |
| 5_0 | 5.0 | Slightly lower quality vs 6.5, but usable |
| 4_25 | 4.25 | GPTQ equivalent bits per weight, slightly higher quality. |
| 3_5 | 3.5 | Lower quality, only use if you have to. |
git clone --single-branch --branch 6_5 https://huggingface.co/knowledgator_-_Qwen-encoder-0.5B-exl2 Qwen-encoder-0.5B-6_5pip3 install huggingface-hub--revision parameter. For example, to download the 6.5 bpw branch:
Linux:huggingface-cli download knowledgator_-_Qwen-encoder-0.5B-exl2 --revision 6_5 --local-dir Qwen-encoder-0.5B-6_5 --local-dir-use-symlinks Falsehuggingface-cli download knowledgator_-_Qwen-encoder-0.5B-exl2 --revision 6_5 --local-dir Qwen-encoder-0.5B-6.5 --local-dir-use-symlinks FalseLLM2Vec is a simple recipe to convert decoder-only LLMs into text encoders. It consists of 3 simple steps: 1) enabling bidirectional attention, 2) masked next token prediction, and 3) unsupervised contrastive learning. The model can be further fine-tuned to achieve state-of-the-art performance.
pip install llm2vec1from llm2vec.models import Qwen2BiModel
2
3import torch
4from transformers import AutoTokenizer
5
6# Loading base Mistral model, along with custom code that enables bidirectional connections in decoder-only LLMs. MNTP LoRA weights are merged into the base model.
7tokenizer = AutoTokenizer.from_pretrained(
8 "knowledgator/Qwen-encoder-0.5B"
9)
10
11model = Qwen2BiModel.from_pretrained("knowledgator/Qwen-encoder-0.5B")
12
13text = "The quick brown fox jumps over the lazy dog."
14
15inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=512)
16
17device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
18model = model.to(device)
19inputs = {k: v.to(device) for k, v in inputs.items()}
20
21with torch.no_grad():
22 outputs = model(**inputs)
23
24last_hidden_states = outputs.last_hidden_state1git clone https://github.com/Knowledgator/llm2vec.git
2cd llm2vec
3pip install -e .-e flag installs the package in editable mode, which is useful for development.1from llm2vec import (
2 AutoLLMEncoderForSequenceClassification,
3 AutoLLMEncoderForQuestionAnswering,
4 AutoLLMEncoderForTokenClassification
5)
6
7# Load models for different tasks
8classification_model = AutoLLMEncoderForSequenceClassification.from_pretrained('knowledgator/Qwen-encoder-0.5B')
9question_answering_model = AutoLLMEncoderForQuestionAnswering.from_pretrained('knowledgator/Qwen-encoder-0.5B')
10token_classification_model = AutoLLMEncoderForTokenClassification.from_pretrained('knowledgator/Qwen-encoder-0.5B')1from transformers import AutoTokenizer
2
3# Load tokenizer
4tokenizer = AutoTokenizer.from_pretrained('knowledgator/Qwen-encoder-0.5B')
5
6# Prepare input
7text = "This movie is great!"
8inputs = tokenizer(text, return_tensors="pt")
9
10# Get classification logits
11outputs = classification_model(**inputs)
12logits = outputs.logits
13
14# The logits can be used with a softmax function to get probabilities
15# or you can use torch.argmax(logits, dim=1) to get the predicted classdatasets library.Trainer class from HuggingFace's transformers library to fine-tune the model.1from transformers import Trainer, TrainingArguments
2from datasets import load_dataset
3
4# Load your dataset
5dataset = load_dataset("your_dataset")
6
7# Define training arguments
8training_args = TrainingArguments(
9 output_dir="./results",
10 num_train_epochs=3,
11 per_device_train_batch_size=8,
12 per_device_eval_batch_size=8,
13 warmup_steps=500,
14 weight_decay=0.01,
15 logging_dir="./logs",
16)
17
18# Initialize Trainer
19trainer = Trainer(
20 model=classification_model,
21 args=training_args,
22 train_dataset=dataset["train"],
23 eval_dataset=dataset["test"],
24)
25
26# Fine-tune the model
27trainer.train()