krishnateja95 commited on
Commit
0137b78
·
verified ·
1 Parent(s): 2b0a750

Upload folder using huggingface_hub

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 ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - multilingual
4
+ base_model:
5
+ - Qwen/Qwen3-8B
6
+ pipeline_tag: text-generation
7
+ tags:
8
+ - qwen
9
+ - qwen3
10
+ - fp8
11
+ - vllm
12
+ - conversational
13
+ - text-generation-inference
14
+ - llm-compressor
15
+ license: apache-2.0
16
+ ---
17
+
18
+ ## Model Overview
19
+ - **Model Architecture:** Qwen3ForCausalLM
20
+ - **Input:** Text
21
+ - **Output:** Text
22
+ - **Model Optimizations:**
23
+ - **Activation quantization:** FP8
24
+ - **Weight quantization:** FP8
25
+ - **Intended Use Cases:** Intended for commercial and research use. Similarly to the base model, this quantized version is intended for assistant-like chat and multilingual text generation across 100+ languages.
26
+ - **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws).
27
+ - **Version:** 1.0
28
+ - **Model Developers:** RedHat (Neural Magic)
29
+
30
+ ### Model Optimizations
31
+
32
+ This model was obtained by quantizing activations and weights of [Qwen/Qwen3-8B](https://huggingface.co/Qwen/Qwen3-8B) to FP8 data type.
33
+ This optimization reduces the number of bits used to represent weights and activations from 16 to 8, reducing GPU memory requirements (by approximately 50%) and increasing matrix-multiply compute throughput (by approximately 2x).
34
+ Weight quantization also reduces disk size requirements by approximately 50%.
35
+
36
+ Only weights and activations of the linear operators within transformers blocks are quantized.
37
+ Weights are quantized with a symmetric static per-channel scheme, whereas activations are quantized with a symmetric dynamic per-token scheme.
38
+ The [llm-compressor](https://github.com/vllm-project/llm-compressor) library is used for quantization.
39
+
40
+ ## Deployment
41
+
42
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
43
+
44
+ ```python
45
+ from vllm import LLM, SamplingParams
46
+ from transformers import AutoTokenizer
47
+
48
+ model_id = "inference-optimization/Qwen3-8B-FP8-Dynamic"
49
+ number_gpus = 1
50
+ sampling_params = SamplingParams(temperature=0.6, top_p=0.95, top_k=20, min_p=0, max_tokens=256)
51
+
52
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
53
+ messages = [{"role": "user", "content": "Give me a short introduction to large language model."}]
54
+ prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
55
+
56
+ llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
57
+ outputs = llm.generate(prompts, sampling_params)
58
+ generated_text = outputs[0].outputs[0].text
59
+ print(generated_text)
60
+ ```
61
+
62
+ ## Creation
63
+
64
+ <details>
65
+ <summary>Creation details</summary>
66
+
67
+ This model was created with [llm-compressor](https://github.com/vllm-project/llm-compressor) by running the code snippet below.
68
+
69
+ ```python
70
+ from compressed_tensors.offload import dispatch_model
71
+ from transformers import AutoModelForCausalLM, AutoTokenizer
72
+
73
+ from llmcompressor import oneshot
74
+ from llmcompressor.modifiers.quantization import QuantizationModifier
75
+
76
+ MODEL_ID = "Qwen/Qwen3-8B"
77
+
78
+ # Load model.
79
+ model = AutoModelForCausalLM.from_pretrained(
80
+ MODEL_ID,
81
+ low_cpu_mem_usage=True,
82
+ )
83
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
84
+
85
+ recipe = QuantizationModifier(
86
+ targets=["Linear"],
87
+ scheme="FP8_DYNAMIC",
88
+ ignore=["lm_head"],
89
+ )
90
+
91
+ # Apply quantization.
92
+ oneshot(model=model, recipe=recipe)
93
+
94
+ print("========== SAMPLE GENERATION ==============")
95
+ dispatch_model(model)
96
+ input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(model.device)
97
+ output = model.generate(input_ids, max_new_tokens=20)
98
+ print(tokenizer.decode(output[0]))
99
+ print("==========================================")
100
+
101
+ SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-FP8-Dynamic"
102
+ model.save_pretrained(SAVE_DIR)
103
+ tokenizer.save_pretrained(SAVE_DIR)
104
+ ```
105
+ </details>
chat_template.jinja ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0].role == 'system' %}
4
+ {{- messages[0].content + '\n\n' }}
5
+ {%- endif %}
6
+ {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
7
+ {%- for tool in tools %}
8
+ {{- "\n" }}
9
+ {{- tool | tojson }}
10
+ {%- endfor %}
11
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
12
+ {%- else %}
13
+ {%- if messages[0].role == 'system' %}
14
+ {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
15
+ {%- endif %}
16
+ {%- endif %}
17
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
18
+ {%- for message in messages[::-1] %}
19
+ {%- set index = (messages|length - 1) - loop.index0 %}
20
+ {%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
21
+ {%- set ns.multi_step_tool = false %}
22
+ {%- set ns.last_query_index = index %}
23
+ {%- endif %}
24
+ {%- endfor %}
25
+ {%- for message in messages %}
26
+ {%- if message.content is string %}
27
+ {%- set content = message.content %}
28
+ {%- else %}
29
+ {%- set content = '' %}
30
+ {%- endif %}
31
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
32
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
33
+ {%- elif message.role == "assistant" %}
34
+ {%- set reasoning_content = '' %}
35
+ {%- if message.reasoning_content is string %}
36
+ {%- set reasoning_content = message.reasoning_content %}
37
+ {%- else %}
38
+ {%- if '</think>' in content %}
39
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
40
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
41
+ {%- endif %}
42
+ {%- endif %}
43
+ {%- if loop.index0 > ns.last_query_index %}
44
+ {%- if loop.last or (not loop.last and reasoning_content) %}
45
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
46
+ {%- else %}
47
+ {{- '<|im_start|>' + message.role + '\n' + content }}
48
+ {%- endif %}
49
+ {%- else %}
50
+ {{- '<|im_start|>' + message.role + '\n' + content }}
51
+ {%- endif %}
52
+ {%- if message.tool_calls %}
53
+ {%- for tool_call in message.tool_calls %}
54
+ {%- if (loop.first and content) or (not loop.first) %}
55
+ {{- '\n' }}
56
+ {%- endif %}
57
+ {%- if tool_call.function %}
58
+ {%- set tool_call = tool_call.function %}
59
+ {%- endif %}
60
+ {{- '<tool_call>\n{"name": "' }}
61
+ {{- tool_call.name }}
62
+ {{- '", "arguments": ' }}
63
+ {%- if tool_call.arguments is string %}
64
+ {{- tool_call.arguments }}
65
+ {%- else %}
66
+ {{- tool_call.arguments | tojson }}
67
+ {%- endif %}
68
+ {{- '}\n</tool_call>' }}
69
+ {%- endfor %}
70
+ {%- endif %}
71
+ {{- '<|im_end|>\n' }}
72
+ {%- elif message.role == "tool" %}
73
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
74
+ {{- '<|im_start|>user' }}
75
+ {%- endif %}
76
+ {{- '\n<tool_response>\n' }}
77
+ {{- content }}
78
+ {{- '\n</tool_response>' }}
79
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
80
+ {{- '<|im_end|>\n' }}
81
+ {%- endif %}
82
+ {%- endif %}
83
+ {%- endfor %}
84
+ {%- if add_generation_prompt %}
85
+ {{- '<|im_start|>assistant\n' }}
86
+ {%- if enable_thinking is defined and enable_thinking is false %}
87
+ {{- '<think>\n\n</think>\n\n' }}
88
+ {%- endif %}
89
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3ForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 151643,
8
+ "dtype": "bfloat16",
9
+ "eos_token_id": 151645,
10
+ "head_dim": 128,
11
+ "hidden_act": "silu",
12
+ "hidden_size": 4096,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 12288,
15
+ "layer_types": [
16
+ "full_attention",
17
+ "full_attention",
18
+ "full_attention",
19
+ "full_attention",
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
+ "full_attention",
49
+ "full_attention",
50
+ "full_attention",
51
+ "full_attention"
52
+ ],
53
+ "max_position_embeddings": 40960,
54
+ "max_window_layers": 36,
55
+ "model_type": "qwen3",
56
+ "num_attention_heads": 32,
57
+ "num_hidden_layers": 36,
58
+ "num_key_value_heads": 8,
59
+ "pad_token_id": null,
60
+ "quantization_config": {
61
+ "config_groups": {
62
+ "group_0": {
63
+ "format": "float-quantized",
64
+ "input_activations": {
65
+ "actorder": null,
66
+ "block_structure": null,
67
+ "dynamic": true,
68
+ "group_size": null,
69
+ "num_bits": 8,
70
+ "observer": null,
71
+ "observer_kwargs": {},
72
+ "scale_dtype": null,
73
+ "strategy": "token",
74
+ "symmetric": true,
75
+ "type": "float",
76
+ "zp_dtype": null
77
+ },
78
+ "output_activations": null,
79
+ "targets": [
80
+ "Linear"
81
+ ],
82
+ "weights": {
83
+ "actorder": null,
84
+ "block_structure": null,
85
+ "dynamic": false,
86
+ "group_size": null,
87
+ "num_bits": 8,
88
+ "observer": "memoryless_minmax",
89
+ "observer_kwargs": {},
90
+ "scale_dtype": null,
91
+ "strategy": "channel",
92
+ "symmetric": true,
93
+ "type": "float",
94
+ "zp_dtype": null
95
+ }
96
+ }
97
+ },
98
+ "format": "float-quantized",
99
+ "global_compression_ratio": null,
100
+ "ignore": [
101
+ "lm_head"
102
+ ],
103
+ "kv_cache_scheme": null,
104
+ "quant_method": "compressed-tensors",
105
+ "quantization_status": "compressed",
106
+ "sparsity_config": {},
107
+ "transform_config": {},
108
+ "version": "0.17.2.a20260626"
109
+ },
110
+ "rms_norm_eps": 1e-06,
111
+ "rope_parameters": {
112
+ "rope_theta": 1000000,
113
+ "rope_type": "default"
114
+ },
115
+ "sliding_window": null,
116
+ "tie_word_embeddings": false,
117
+ "transformers_version": "5.12.1",
118
+ "use_cache": true,
119
+ "use_sliding_window": false,
120
+ "vocab_size": 151936
121
+ }
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "temperature": 0.6,
10
+ "top_k": 20,
11
+ "top_p": 0.95,
12
+ "transformers_version": "5.12.1"
13
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:248d659794b5143f59e065dd690b6f5b05ee09403551823b93e88b972eda6833
3
+ size 9438581928
recipe.yaml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ default_stage:
2
+ default_modifiers:
3
+ QuantizationModifier:
4
+ targets: [Linear]
5
+ ignore: [lm_head]
6
+ scheme: FP8_DYNAMIC
7
+ bypass_divisibility_checks: false
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be75606093db2094d7cd20f3c2f385c212750648bd6ea4fb2bf507a6a4c55506
3
+ size 11422650
tokenizer_config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "extra_special_tokens": [
9
+ "<|im_start|>",
10
+ "<|im_end|>",
11
+ "<|object_ref_start|>",
12
+ "<|object_ref_end|>",
13
+ "<|box_start|>",
14
+ "<|box_end|>",
15
+ "<|quad_start|>",
16
+ "<|quad_end|>",
17
+ "<|vision_start|>",
18
+ "<|vision_end|>",
19
+ "<|vision_pad|>",
20
+ "<|image_pad|>",
21
+ "<|video_pad|>"
22
+ ],
23
+ "is_local": false,
24
+ "local_files_only": false,
25
+ "model_max_length": 131072,
26
+ "pad_token": "<|endoftext|>",
27
+ "split_special_tokens": false,
28
+ "tokenizer_class": "Qwen2Tokenizer",
29
+ "unk_token": null
30
+ }