-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiLo_compress_DeepSeek.py
More file actions
37 lines (30 loc) · 1.49 KB
/
Copy pathMiLo_compress_DeepSeek.py
File metadata and controls
37 lines (30 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import torch
from transformers import AutoModelForCausalLM
from MiLo.models.hf.deepseek import DeepSeekMoEMiLo as AutoMiLoHFModel
from MiLo.core.quantize import *
def main():
device = "cuda"
save_dir = "/DeepSeek_MiLo_s1"
compress_config = BaseCompressConfig(
# quantization config
nbits = 3,
group_size = 64,
quant_scale = False,
quant_zero = False,
axis = 1,
# compensator config
iter = 10,
sparse_rank = 16,
dense_rank = 512,
rank_strategy = None,
compensator_dtype = "int3"
)
model = AutoModelForCausalLM.from_pretrained("deepseek-ai/deepseek-moe-16b-base",
torch_dtype=torch.float16,
trust_remote_code=True)
AutoMiLoHFModel.compress_model(model,
compress_config=compress_config,
device=device)
AutoMiLoHFModel.save_compressed(model, save_dir)
if __name__ == "__main__":
main()