Model Details

This model is an int4 model with group_size 128 and symmetric quantization of deepseek-ai/DeepSeek-V3 generated by intel/auto-round algorithm.

Please note this model may introduce overflow issue cuased by FP16 kernel , which is tipically used on cuda device. Additionally, loading the model in Transformers can be quite slow. Consider using an alternative serving framework that could run int4 models with bf16 computing dtype.

Due to limited GPU resources, we have only tested a few prompts on a CPU backend with QBits. If this model does not meet your performance expectations, you may explore another quantized model in AWQ format, generated via AutoRound with different hyperparameters. This alternative model will be uploaded soon.

Please follow the license of the original model.

How To Use

INT4 Inference on CPU with Qbits(Recommend)

pip3 install auto-round (it will install intel-extension-for-pytorch and intel-extension-for-transformers both). For intel cpu, it will prioritize using intel-extension-for-pytorch , for other cpus, it will prioritize using intel-extension-for-transformers.

To make sure to use qbits with intel-extension-for-transformers, please uninstall intel-extension-for-pytorch

intel-extension-for-transformers faster repacking, slower inference,higher accuracy intel-extension-for-pytorch much slower repacking, faster inferecne, lower accuracy

from auto_round import AutoRoundConfig ##must import for autoround format
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

quantized_model_dir = "tonyshark/deepseek-v3-int4-cpu"
quantization_config = AutoRoundConfig(
    backend="cpu"
)
model = AutoModelForCausalLM.from_pretrained(
    quantized_model_dir,
    torch_dtype=torch.bfloat16,
    trust_remote_code=True,
    device_map="cpu",
    revision="8fe0735",##use autoround format, the only difference is config.json
    quantization_config = quantization_config, ##cpu only machine don't need to set this value
    
)

tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir,trust_remote_code=True)
prompt = "There is a girl who likes adventure,"
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

generated_ids = model.generate(
    model_inputs.input_ids,
    max_new_tokens=200,  ##change this to align with the official usage
    do_sample=False  ##change this to align with the official usage
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)

"""

prompt = "How many r in strawberry."
##INT4 
"""The word "strawberry" contains **3 "r"s.
"""

prompt = "There is a girl who likes adventure,"
##INT4:
"""That's wonderful! A girl who loves adventure is likely curious, brave, and eager to explore the world around her. Here are some ideas to fuel her adventurous spirit:

### **Outdoor Adventures**

- **Hiking:** Explore local trails, national parks, or mountains.
- **Camping:** Spend a night under the stars and connect with nature.
- **Rock Climbing:** Challenge herself with bouldering or climbing walls.
- **Kayaking/Canoeing:** Paddle through rivers, lakes, or even the ocean.
- **Zip-lining:** Soar through the treetops for an adrenaline rush.

### **Travel Adventures**

- **Road Trips:** Plan a journey to new cities or scenic destinations.
- **Backpacking:** Travel light and explore different cultures and landscapes.
- **Volunteer Abroad:** Combine adventure with helping others in a new country.

### **Creative Adventures**

- **Photography:** Capture the beauty
"""

prompt = "Please give a brief introduction of DeepSeek company."
##INT4:
"""DeepSeek Artificial Intelligence Co., Ltd. (referred to as "DeepSeek" or "深度求索") , founded in 2023, is a Chinese company dedicated to making AGI a reality"""

INT4 Inference on CUDA(have not tested, maybe need 8X80G GPU)

BF16 int4 kernel is required.

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
quantized_model_dir = " tonyshark/deepseek-v3-int4-cpu"

model = AutoModelForCausalLM.from_pretrained(
    quantized_model_dir,
    torch_dtype=torch.float16,
    trust_remote_code=True,
    device_map="auto"
    
)

tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir,trust_remote_code=True)
prompt = "There is a girl who likes adventure,"
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

generated_ids = model.generate(
    model_inputs.input_ids,
    max_new_tokens=200,  ##change this to align with the official usage
    do_sample=False  ##change this to align with the official usage
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)

Evaluate the model

we have no enough resource to evaluate the model

Generate the model

need 200G GPU memory, details will be updated later

Ethical Considerations and Limitations

The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.

Therefore, before deploying any applications of the model, developers should perform safety testing.

Caveats and Recommendations

Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.

Here are a couple of useful links to learn more about Intel's AI software:

  • Intel Neural Compressor link

Disclaimer

The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.

Cite

@article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }

arxiv github

Downloads last month
38
Inference API
Unable to determine this model's library. Check the docs .

Model tree for tonyshark/deepseek-v3-int4-cpu

Quantized
(5)
this model

Dataset used to train tonyshark/deepseek-v3-int4-cpu