manu02 commited on
Commit
ad8b057
·
verified ·
1 Parent(s): df70ea0

Upload 4-bit quantized version of perplexity-ai/pplx-embed-v1-0.6b with 64.7% memory reduction

Browse files
Files changed (8) hide show
  1. .gitattributes +1 -0
  2. README.md +37 -0
  3. config.json +83 -0
  4. configuration.py +5 -0
  5. model.safetensors +3 -0
  6. modeling.py +83 -0
  7. tokenizer.json +3 -0
  8. tokenizer_config.json +16 -0
.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 ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: perplexity-ai/pplx-embed-v1-0.6b
3
+ language: en
4
+ license: apache-2.0
5
+ tags:
6
+ - quantized
7
+ - 4bit
8
+ - bnb
9
+ - transformers
10
+ model_name: pplx-embed-v1-0.6b-bnb-4bit-nf4
11
+ ---
12
+
13
+ # pplx-embed-v1-0.6b (Quantized)
14
+
15
+ ## Description
16
+ This model is a 4-bit quantized version of the original [`perplexity-ai/pplx-embed-v1-0.6b`](https://huggingface.co/perplexity-ai/pplx-embed-v1-0.6b) model, optimized for reduced memory usage while maintaining performance.
17
+
18
+ ## Quantization Details
19
+ - **Quantization Type**: 4-bit
20
+ - **bnb_4bit_quant_type**: nf4
21
+ - **bnb_4bit_use_double_quant**: True
22
+ - **bnb_4bit_compute_dtype**: bfloat16
23
+ - **bnb_4bit_quant_storage**: uint8
24
+ - **Original Footprint**: 2384.20 MB (FLOAT32)
25
+ - **Quantized Footprint**: 842.79 MB (UINT8)
26
+ - **Memory Reduction**: 64.7%
27
+
28
+ ## Usage
29
+ ```python
30
+ from transformers import AutoModel, AutoTokenizer
31
+
32
+ model_name = "pplx-embed-v1-0.6b-bnb-4bit-nf4"
33
+ model = AutoModel.from_pretrained(
34
+ "manu02/pplx-embed-v1-0.6b-bnb-4bit-nf4",
35
+ )
36
+ tokenizer = AutoTokenizer.from_pretrained("manu02/pplx-embed-v1-0.6b-bnb-4bit-nf4", use_fast=True)
37
+ ```
config.json ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "PPLXQwen3Model"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "auto_map": {
8
+ "AutoConfig": "configuration.PPLXQwen3Config",
9
+ "AutoModel": "modeling.PPLXQwen3Model"
10
+ },
11
+ "bos_token_id": 151643,
12
+ "dtype": "float32",
13
+ "eos_token_id": 151643,
14
+ "head_dim": 128,
15
+ "hidden_act": "silu",
16
+ "hidden_size": 1024,
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 3072,
19
+ "layer_types": [
20
+ "full_attention",
21
+ "full_attention",
22
+ "full_attention",
23
+ "full_attention",
24
+ "full_attention",
25
+ "full_attention",
26
+ "full_attention",
27
+ "full_attention",
28
+ "full_attention",
29
+ "full_attention",
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention",
38
+ "full_attention",
39
+ "full_attention",
40
+ "full_attention",
41
+ "full_attention",
42
+ "full_attention",
43
+ "full_attention",
44
+ "full_attention",
45
+ "full_attention",
46
+ "full_attention",
47
+ "full_attention"
48
+ ],
49
+ "max_position_embeddings": 32768,
50
+ "max_window_layers": 28,
51
+ "model_type": "bidirectional_pplx_qwen3",
52
+ "num_attention_heads": 16,
53
+ "num_hidden_layers": 28,
54
+ "num_key_value_heads": 8,
55
+ "pad_token_id": null,
56
+ "quantization_config": {
57
+ "_load_in_4bit": true,
58
+ "_load_in_8bit": false,
59
+ "bnb_4bit_compute_dtype": "bfloat16",
60
+ "bnb_4bit_quant_storage": "uint8",
61
+ "bnb_4bit_quant_type": "nf4",
62
+ "bnb_4bit_use_double_quant": true,
63
+ "llm_int8_enable_fp32_cpu_offload": false,
64
+ "llm_int8_has_fp16_weight": false,
65
+ "llm_int8_skip_modules": null,
66
+ "llm_int8_threshold": 6.0,
67
+ "load_in_4bit": true,
68
+ "load_in_8bit": false,
69
+ "quant_method": "bitsandbytes"
70
+ },
71
+ "rms_norm_eps": 1e-06,
72
+ "rope_parameters": {
73
+ "rope_theta": 1000000,
74
+ "rope_type": "default"
75
+ },
76
+ "sliding_window": null,
77
+ "tie_word_embeddings": true,
78
+ "transformers_version": "5.2.0.dev0",
79
+ "use_bidirectional_attention": true,
80
+ "use_cache": false,
81
+ "use_sliding_window": false,
82
+ "vocab_size": 151936
83
+ }
configuration.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ from transformers.models.qwen3.configuration_qwen3 import Qwen3Config
2
+
3
+
4
+ class PPLXQwen3Config(Qwen3Config):
5
+ model_type = "bidirectional_pplx_qwen3"
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ccb52a10a1fc0fb4207c742dd145ef35ffa9083cbde8895b3d303152ab27abed
3
+ size 850175239
modeling.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Callable
2
+ import torch
3
+ from transformers import Qwen3Model
4
+ from transformers.cache_utils import Cache
5
+ from transformers.masking_utils import create_causal_mask
6
+ from transformers.modeling_outputs import BaseModelOutputWithPooling
7
+ from transformers.processing_utils import Unpack
8
+ from transformers.utils import TransformersKwargs
9
+ from .configuration import PPLXQwen3Config
10
+
11
+
12
+ # From modeling_t5gemma.py
13
+ def bidirectional_mask_function(attention_mask: torch.Tensor | None) -> Callable:
14
+ """
15
+ This creates bidirectional attention mask.
16
+ """
17
+
18
+ def inner_mask(batch_idx: int, head_idx: int, q_idx: int, kv_idx: int) -> bool:
19
+ if attention_mask is None:
20
+ return torch.ones((), dtype=torch.bool)
21
+ return attention_mask[batch_idx, kv_idx].to(torch.bool)
22
+
23
+ return inner_mask
24
+
25
+
26
+ class PPLXQwen3Model(Qwen3Model):
27
+ _supports_flash_attn = True
28
+ _supports_sdpa = True
29
+
30
+ config_class = PPLXQwen3Config
31
+
32
+ def __init__(self, config):
33
+ super().__init__(config)
34
+ self.post_init()
35
+
36
+ def post_init(self):
37
+ super().post_init()
38
+ # Override to set all layers to non-causal attention. This'll work with attn_implementation="flash_attention_2" or "sdpa"
39
+ for layer in self.layers:
40
+ layer.self_attn.is_causal = False
41
+
42
+ def forward(
43
+ self,
44
+ input_ids: torch.LongTensor | None = None,
45
+ attention_mask: torch.Tensor | None = None,
46
+ position_ids: torch.LongTensor | None = None,
47
+ past_key_values: Cache | None = None,
48
+ inputs_embeds: torch.FloatTensor | None = None,
49
+ use_cache: bool | None = None,
50
+ cache_position: torch.LongTensor | None = None,
51
+ **kwargs: Unpack[TransformersKwargs],
52
+ ) -> BaseModelOutputWithPooling:
53
+ if inputs_embeds is None:
54
+ inputs_embeds = self.embed_tokens(input_ids)
55
+ input_ids = None
56
+
57
+ # We construct a dummy tensor imitating initial positions
58
+ dummy_cache_position = torch.arange(
59
+ inputs_embeds.shape[1], device=inputs_embeds.device, dtype=torch.long
60
+ )
61
+ attention_mask = {
62
+ "full_attention": create_causal_mask(
63
+ config=self.config,
64
+ input_embeds=inputs_embeds,
65
+ attention_mask=attention_mask,
66
+ cache_position=dummy_cache_position,
67
+ past_key_values=None,
68
+ position_ids=position_ids,
69
+ or_mask_function=bidirectional_mask_function(attention_mask),
70
+ )
71
+ }
72
+
73
+ outputs = super().forward(
74
+ input_ids=input_ids,
75
+ attention_mask=attention_mask,
76
+ position_ids=position_ids,
77
+ past_key_values=past_key_values,
78
+ inputs_embeds=inputs_embeds,
79
+ use_cache=use_cache,
80
+ cache_position=cache_position,
81
+ **kwargs,
82
+ )
83
+ return outputs
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c6fb5c5bbba5fa5f8332edfb6d8aa67bd7fb3d75365b1765f108201698eaebf5
3
+ size 11422837
tokenizer_config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|endoftext|>",
7
+ "errors": "replace",
8
+ "is_local": false,
9
+ "mask_token": "â½Ĺ",
10
+ "model_max_length": 131072,
11
+ "pad_token": "<|endoftext|>",
12
+ "sep_token": "<|endoftext|>",
13
+ "split_special_tokens": false,
14
+ "tokenizer_class": "TokenizersBackend",
15
+ "unk_token": null
16
+ }