haoyang-amd commited on
Commit
9f534c0
·
verified ·
1 Parent(s): dd48667

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +74 -0
README.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ base_model:
4
+ - deepseek-ai/DeepSeek-R1-0528
5
+ ---
6
+
7
+ **Note that the MTP layers of this model are also PTPC-quantized.**
8
+
9
+ # Model Overview
10
+
11
+ - **Model Architecture:** DeepSeek-R1-0528
12
+ - **Input:** Text
13
+ - **Output:** Text
14
+ - **Supported Hardware Microarchitecture:** AMD MI350/MI355
15
+ - **ROCm**: 7.0
16
+ - **Operating System(s):** Linux
17
+ - **Inference Engine:** [SGLang](https://docs.sglang.ai/)/[vLLM](https://docs.vllm.ai/en/latest/)
18
+ - **Model Optimizer:** [AMD-Quark](https://quark.docs.amd.com/latest/index.html) (V0.10)
19
+ - **Weight quantization:** Perchannel, FP8E4M3, Static
20
+ - **Activation quantization:** Pertoken, FP8E4M3, Dynamic
21
+ - **Calibration Dataset:** [Pile](https://huggingface.co/datasets/mit-han-lab/pile-val-backup)
22
+
23
+ This model was built with deepseek-ai DeepSeek-R1-0528 model by applying [AMD-Quark](https://quark.docs.amd.com/latest/index.html) for FP8E4M3 PTPC quantization.
24
+
25
+ # Model Quantization
26
+
27
+ The model was quantized from [deepseek-ai/DeepSeek-R1-0528](https://huggingface.co/deepseek-ai/DeepSeek-R1-0528) using [AMD-Quark](https://quark.docs.amd.com/latest/index.html). The weights are quantized to FP8 and activations are quantized to FP8.
28
+
29
+ **Preprocessing requirement:**
30
+
31
+ Before executing the quantization script below, the original FP8 model must first be dequantized to BFloat16.
32
+ You can either perform the dequantization manually using this [conversion script](https://github.com/deepseek-ai/DeepSeek-V3/blob/main/inference/fp8_cast_bf16.py), or use the pre-converted BFloat16 model available at [unsloth/DeepSeek-R1-0528-BF16](https://huggingface.co/unsloth/DeepSeek-R1-0528-BF16).
33
+ You need to manually modify the transformers so that it can load the MTP layer. You can also directly use our modified model [amd/DeepSeek-R1-0528-BF16](https://huggingface.co/amd/DeepSeek-R1-0528-BF16) to perform quantitative analysis.
34
+
35
+ **Quantization scripts:**
36
+ ```
37
+ # pip install amd-quark
38
+
39
+ from transformers import AutoTokenizer, AutoModelForCausalLM
40
+ from quark.torch import ModelQuantizer, export_safetensors
41
+ from quark.torch.quantization import FP8E4M3PerChannelSpec
42
+ from quark.torch.quantization.config.config import Config, QuantizationConfig
43
+
44
+ ckpt_path = "amd/DeepSeek-R1-0528-BF16"
45
+ exclude_layers = ["lm_head","*mlp.gate", "model.layers.61.eh_proj", "model.layers.61.shared_head.head"]
46
+ output_dir = ckpt_path.rstrip("/").split("/")[-1] + "-ptpc"
47
+
48
+ # Load the original floating-point model
49
+ model = AutoModelForCausalLM.from_pretrained(ckpt_path, device_map="auto", torch_dtype="auto", trust_remote_code=True)
50
+ model.eval()
51
+ tokenizer = AutoTokenizer.from_pretrained(ckpt_path)
52
+
53
+ # Set the quantization configuration
54
+ FP8_PER_CHANNEL_SPEC = FP8E4M3PerChannelSpec(is_dynamic=False, ch_axis=0).to_quantization_spec()
55
+ FP8_PER_TOKEN_DYNAMIC_SPEC = FP8E4M3PerChannelSpec(is_dynamic=True, ch_axis=1).to_quantization_spec()
56
+ W_FP8_PER_CHANNEL_STATIC_A_FP8_PER_TOKEN_DYNAMIC_CONFIG = QuantizationConfig(input_tensors=FP8_PER_TOKEN_DYNAMIC_SPEC, weight=FP8_PER_CHANNEL_SPEC)
57
+ quant_config = Config(global_quant_config=W_FP8_PER_CHANNEL_STATIC_A_FP8_PER_TOKEN_DYNAMIC_CONFIG, exclude=exclude_layers)
58
+
59
+ # Apply quantization
60
+ quantizer = ModelQuantizer(quant_config)
61
+ model = quantizer.quantize_model(model)
62
+
63
+ # Export quantized model
64
+ model = quantizer.freeze(model)
65
+ export_safetensors(model, output_dir)
66
+ tokenizer.save_pretrained(output_dir)
67
+ ```
68
+
69
+ # Deployment
70
+
71
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backends.
72
+
73
+ # License
74
+ Modifications Copyright(c) 2025 Advanced Micro Devices, Inc. All rights reserved.