Views
No views yet
ai-sage/Giga-Embeddings-instruct, created using bitsandbytes with the following configuration:1bnb_cfg = BitsAndBytesConfig(
2 load_in_4bit=True,
3 bnb_4bit_quant_type="nf4",
4 bnb_4bit_use_double_quant=True,
5 bnb_4bit_compute_dtype=torch.bfloat16
6)⚠️ Note: This model is not fine-tuned — it is the original model loaded in 4-bit precision usingtransformers+bitsandbytes. It requiresbitsandbytesandaccelerateto run.
1from transformers import AutoModel, AutoTokenizer, BitsAndBytesConfig
2import torch
3
4bnb_cfg = BitsAndBytesConfig(
5 load_in_4bit=True,
6 bnb_4bit_quant_type="nf4",
7 bnb_4bit_use_double_quant=True,
8 bnb_4bit_compute_dtype=torch.bfloat16
9)
10
11model = AutoModel.from_pretrained(
12 "iMiW/Giga-Embeddings-instruct-4bit-nf4",
13 quantization_config=bnb_cfg,
14 trust_remote_code=True
15)
16tokenizer = AutoTokenizer.from_pretrained(
17 "iMiW/Giga-Embeddings-instruct-4bit-nf4",
18 trust_remote_code=True
19)
20
21def get_detailed_instruct(task_description: str, query: str) -> str:
22 return f'Instruct: {task_description}\nQuery: {query}'
23
24# Each query must come with a one-sentence instruction that describes the task
25task = 'Given a web search query, retrieve relevant passages that answer the query'
26
27queries = [
28 get_detailed_instruct(task, 'What is the capital of Russia?'),
29 get_detailed_instruct(task, 'Explain gravity')
30]
31# No need to add instruction for retrieval documents
32documents = [
33 "The capital of Russia is Moscow.",
34 "Gravity is a force that attracts two bodies towards each other. It gives weight to physical objects and is responsible for the movement of planets around the sun."
35]
36input_texts = queries + documents
37
38model.eval()
39model.cuda()
40
41max_length = 4096
42
43# Tokenize the input texts
44batch_dict = tokenizer(
45 input_texts,
46 padding=True,
47 truncation=True,
48 max_length=max_length,
49 return_tensors="pt",
50)
51batch_dict.to(model.device)
52embeddings = model(**batch_dict, return_embeddings=True)
53
54scores = (embeddings[:2] @ embeddings[2:].T)
55print(scores.tolist())