Skip to content

add DeekSeek and Kimi-K2; support per-tensor and w4a8; support batch calibration in fp8 low_memory_run; support multiple nodes#29

Merged
yghstill merged 3 commits into
Tencent:mainfrom
ali-88123:dev_cen
Aug 6, 2025
Merged

add DeekSeek and Kimi-K2; support per-tensor and w4a8; support batch calibration in fp8 low_memory_run; support multiple nodes#29
yghstill merged 3 commits into
Tencent:mainfrom
ali-88123:dev_cen

Conversation

@ali-88123

Copy link
Copy Markdown
Collaborator
  • 增加DeepSeek和Kimi-K2的per-tensor量化和w4a8量化,config目录名称deepseek_r1

  • 支持权重以fp8和bf16的方式加载,使用load_type参数传入,可单卡、单机8卡、多机多卡校准

  • 修改fp8的low_memory_run函数,支持batch校准

for i in range(0, nsamples, bs):
            inps = self.inps[i : i + bs, :, :].to(dev)
            outs = torch.zeros_like(inps).to(dev)
            for j in range(len(layers)):
                layer = layers[j].to(dev)
  • run.py中增加multi_node_run函数,传入--multi-nodes参数实现多机多卡模式
if args.input_prompt:
        infer(config, args.input_prompt)
    elif args.multi_nodes:
        multi_node_run(config)
    else:
        run(config)
  • 增加DeepSeek量化说明文档

Comment thread angelslim/compressor/quant/core/save.py Outdated
},
}

from transformers.models.deepseek_v3 import DeepseekV3Config

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import 放在文件起始位置

Comment thread angelslim/compressor/quant/core/save.py Outdated
new_k = "model.norm.weight"
new_save_dict[new_k] = param
index_dict["weight_map"][new_k] = str(filename)
# safe_save(new_save_dict, os.path.join(save_model_path, filename)) # SAVE

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean注释内容

Comment thread angelslim/compressor/quant/core/save.py Outdated
json.dump(new_model_index, f, indent=2)


class PTQSaveTRTLLM(Deepseekv3HfPTQSave):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个不是通用的save函数吧,如果只适用于DeepSeek,可以增加DeepSeek前缀

Comment thread angelslim/models/base_model.py Outdated
def from_pretrained(
self,
model_path,
model_name="Qwen",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model_name这个参数不需要增加,from_pretrained如果和base model不一致,在Deepseek model下重写就行

Comment thread angelslim/models/base_model.py Outdated
model_path, trust_remote_code=trust_remote_code
)
# Load tokenizer
if config.model_type == "kimi_k2":

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kimi-k2可以新注册一个模型,也写一个from_pretrained

Comment thread angelslim/models/llm/__init__.py Outdated
from .hunyuan_dense import HunyuanDense # noqa: F401
from .hunyuan_moe import HunyuanMoE # noqa: F401
from .llama import Llama # noqa: F401
from .modeling_deepseek import DeepseekV3ForCausalLM # noqa: F401

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeepseekV3ForCausalLM不对外暴露,这里可以删掉

Comment thread angelslim/utils/config_parser.py Outdated
low_cpu_mem_usage: bool = field(default=True)
use_cache: bool = field(default=False)
cache_dir: Optional[str] = field(default=None)
load_type: str = field(default="bf16")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

load_type字段看下是否能复用torch_dtype,Deepseek里加一个判断即可

Comment thread angelslim/utils/config_parser.py Outdated
"int4_awq",
"int4_gptq",
"int8_dynamic",
"w4a8",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> w4a8_fp8

data_path: your/data/path
max_seq_length: 4096
num_samples: 128
batch_size: 1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kimi也新增一个config

@ali-88123 ali-88123 requested review from yghstill and removed request for liusong1222 August 5, 2025 06:22

@yghstill yghstill left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yghstill yghstill merged commit 11dcd71 into Tencent:main Aug 6, 2025
5 checks passed
@ali-88123 ali-88123 deleted the dev_cen branch August 18, 2025 11:47
dawnranger pushed a commit to dawnranger/AngelSlim that referenced this pull request Mar 11, 2026
…calibration in fp8 low_memory_run; support multiple nodes (Tencent#29)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants