scotto2 commited on
Commit
0f75113
·
verified ·
1 Parent(s): bd80b14

Upload 8-bit quantized E5 large instruct model

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,3 +1,70 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Multilingual E5 Large Instruct - 8-bit Quantized
3
+
4
+ This is an 8-bit quantized version of the [intfloat/multilingual-e5-large-instruct](https://huggingface.co/intfloat/multilingual-e5-large-instruct) model.
5
+
6
+ ## Model Details
7
+
8
+ - Original model: [intfloat/multilingual-e5-large-instruct](https://huggingface.co/intfloat/multilingual-e5-large-instruct)
9
+ - Quantization: 8-bit (using bitsandbytes)
10
+ - Model architecture: XLM-RoBERTa Large with instruction tuning
11
+ - Original parameters: 560M
12
+ - Embedding dimensions: 1024
13
+ - Context length: 512 tokens
14
+ - Languages supported: 94+ languages
15
+
16
+ ## Usage
17
+
18
+ This model can be used with the `transformers` library for generating embeddings:
19
+
20
+ ```python
21
+ from transformers import AutoModel, AutoTokenizer
22
+ import torch.nn.functional as F
23
+
24
+ # Load the model
25
+ model_name = "gopersonal/multilingual-e5-large-instruct-8bit"
26
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
27
+ model = AutoModel.from_pretrained(model_name, load_in_8bit=True, device_map="auto")
28
+
29
+ # Define function to get embeddings
30
+ def average_pool(last_hidden_states, attention_mask):
31
+ last_hidden = last_hidden_states.masked_fill(~attention_mask[..., None].bool(), 0.0)
32
+ return last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[..., None]
33
+
34
+ def get_detailed_instruct(task_description, query):
35
+ return f'Instruct: task_description\nQuery: query'
36
+
37
+ # Prepare your texts
38
+ task = 'Given a web search query, retrieve relevant passages that answer the query'
39
+ queries = [
40
+ get_detailed_instruct(task, 'how much protein should a female eat'),
41
+ get_detailed_instruct(task, 'best restaurants in new york')
42
+ ]
43
+
44
+ # Tokenize and generate embeddings
45
+ batch_dict = tokenizer(queries, max_length=512, padding=True, truncation=True, return_tensors='pt')
46
+ outputs = model(**batch_dict)
47
+ embeddings = average_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
48
+
49
+ # Normalize embeddings
50
+ embeddings = F.normalize(embeddings, p=2, dim=1)
51
+ ```
52
+
53
+ ## Infinity Embedding Server Usage
54
+
55
+ ```bash
56
+ docker run --gpus all -v $PWD/models:/app/.cache -p 7997:7997 \
57
+ michaelf34/infinity:latest \
58
+ v2 --model-id gopersonal/multilingual-e5-large-instruct-8bit \
59
+ --dtype int8 --batch-size 8 --engine torch --port 7997 --device auto
60
+ ```
61
+
62
+ ## Benefits of 8-bit Quantization
63
+
64
+ - Approximately 50% reduction in memory usage compared to FP16
65
+ - Faster inference, especially on GPUs with limited VRAM
66
+ - Minimal impact on embedding quality and similarity calculations
67
+
68
+ ## License
69
+
70
+ This model inherits the license of the original model: MIT
config.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "intfloat/multilingual-e5-large-instruct",
3
+ "architectures": [
4
+ "XLMRobertaModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "classifier_dropout": null,
9
+ "eos_token_id": 2,
10
+ "hidden_act": "gelu",
11
+ "hidden_dropout_prob": 0.1,
12
+ "hidden_size": 1024,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 4096,
15
+ "layer_norm_eps": 1e-05,
16
+ "max_position_embeddings": 514,
17
+ "model_type": "xlm-roberta",
18
+ "num_attention_heads": 16,
19
+ "num_hidden_layers": 24,
20
+ "output_past": true,
21
+ "pad_token_id": 1,
22
+ "position_embedding_type": "absolute",
23
+ "quantization_config": {
24
+ "_load_in_4bit": false,
25
+ "_load_in_8bit": true,
26
+ "bnb_4bit_compute_dtype": "float32",
27
+ "bnb_4bit_quant_storage": "uint8",
28
+ "bnb_4bit_quant_type": "fp4",
29
+ "bnb_4bit_use_double_quant": false,
30
+ "llm_int8_enable_fp32_cpu_offload": false,
31
+ "llm_int8_has_fp16_weight": false,
32
+ "llm_int8_skip_modules": null,
33
+ "llm_int8_threshold": 6.0,
34
+ "load_in_4bit": false,
35
+ "load_in_8bit": true,
36
+ "quant_method": "bitsandbytes"
37
+ },
38
+ "torch_dtype": "float16",
39
+ "transformers_version": "4.48.3",
40
+ "type_vocab_size": 1,
41
+ "use_cache": true,
42
+ "vocab_size": 250002
43
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72f89215ff8df34458cf7862a1b3dc23ed9a1094c9e748808be7aad1e64353f6
3
+ size 818751864
sentencepiece.bpe.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cfc8146abe2a0488e9e2a0c56de7952f7c11ab059eca145a0a727afce0db2865
3
+ size 5069051
special_tokens_map.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "cls_token": {
10
+ "content": "<s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "eos_token": {
17
+ "content": "</s>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "mask_token": {
24
+ "content": "<mask>",
25
+ "lstrip": true,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "pad_token": {
31
+ "content": "<pad>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "sep_token": {
38
+ "content": "</s>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false
43
+ },
44
+ "unk_token": {
45
+ "content": "<unk>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false
50
+ }
51
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3a56def25aa40facc030ea8b0b87f3688e4b3c39eb8b45d5702b3a1300fe2a20
3
+ size 17082734
tokenizer_config.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<s>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<pad>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "250001": {
36
+ "content": "<mask>",
37
+ "lstrip": true,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "additional_special_tokens": [],
45
+ "bos_token": "<s>",
46
+ "clean_up_tokenization_spaces": true,
47
+ "cls_token": "<s>",
48
+ "eos_token": "</s>",
49
+ "extra_special_tokens": {},
50
+ "mask_token": "<mask>",
51
+ "model_max_length": 512,
52
+ "pad_token": "<pad>",
53
+ "sep_token": "</s>",
54
+ "tokenizer_class": "XLMRobertaTokenizer",
55
+ "unk_token": "<unk>"
56
+ }