Text Generation
Transformers
Safetensors
deepseek_v2
conversational
custom_code
text-generation-inference
compressed-tensors
Instructions to use nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8
- SGLang
How to use nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8 with Docker Model Runner:
docker model run hf.co/nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model:
|
| 3 |
+
- deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
Created using llm-compressor for use with vLLM:
|
| 7 |
+
```python
|
| 8 |
+
from datasets import load_dataset
|
| 9 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 10 |
+
|
| 11 |
+
from llmcompressor.modifiers.quantization import QuantizationModifier
|
| 12 |
+
from llmcompressor.transformers import oneshot
|
| 13 |
+
|
| 14 |
+
# NOTE: transformers 4.48.0 has an import error with DeepSeek.
|
| 15 |
+
# Please consider either downgrading your transformers version to a
|
| 16 |
+
# previous version or upgrading to a version where this bug is fixed
|
| 17 |
+
|
| 18 |
+
# select a Mixture of Experts model for quantization
|
| 19 |
+
MODEL_ID = "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct"
|
| 20 |
+
|
| 21 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 22 |
+
MODEL_ID, device_map="auto", torch_dtype="auto", trust_remote_code=True
|
| 23 |
+
)
|
| 24 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 25 |
+
|
| 26 |
+
# Select calibration dataset.
|
| 27 |
+
# its recommended to use more calibration samples for MoE models so each expert is hit
|
| 28 |
+
DATASET_ID = "HuggingFaceH4/ultrachat_200k"
|
| 29 |
+
DATASET_SPLIT = "train_sft"
|
| 30 |
+
NUM_CALIBRATION_SAMPLES = 2048
|
| 31 |
+
MAX_SEQUENCE_LENGTH = 2048
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
# Load dataset and preprocess.
|
| 35 |
+
ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
|
| 36 |
+
ds = ds.shuffle(seed=42).select(range(NUM_CALIBRATION_SAMPLES))
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def preprocess(example):
|
| 40 |
+
return {
|
| 41 |
+
"text": tokenizer.apply_chat_template(
|
| 42 |
+
example["messages"],
|
| 43 |
+
tokenize=False,
|
| 44 |
+
)
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
ds = ds.map(preprocess)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
# Tokenize inputs.
|
| 52 |
+
def tokenize(sample):
|
| 53 |
+
return tokenizer(
|
| 54 |
+
sample["text"],
|
| 55 |
+
padding=False,
|
| 56 |
+
max_length=MAX_SEQUENCE_LENGTH,
|
| 57 |
+
truncation=True,
|
| 58 |
+
add_special_tokens=False,
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
ds = ds.map(tokenize, remove_columns=ds.column_names)
|
| 63 |
+
|
| 64 |
+
# define a llmcompressor recipe for FP8 W8A8 quantization
|
| 65 |
+
# since the MoE gate layers are sensitive to quantization, we add them to the ignore
|
| 66 |
+
# list so they remain at full precision
|
| 67 |
+
recipe = [
|
| 68 |
+
QuantizationModifier(
|
| 69 |
+
targets="Linear",
|
| 70 |
+
scheme="FP8",
|
| 71 |
+
ignore=["lm_head", "re:.*mlp.gate$"],
|
| 72 |
+
),
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
SAVE_DIR = MODEL_ID.split("/")[1] + "-FP8"
|
| 76 |
+
|
| 77 |
+
oneshot(
|
| 78 |
+
model=model,
|
| 79 |
+
dataset=ds,
|
| 80 |
+
recipe=recipe,
|
| 81 |
+
max_seq_length=MAX_SEQUENCE_LENGTH,
|
| 82 |
+
num_calibration_samples=NUM_CALIBRATION_SAMPLES,
|
| 83 |
+
trust_remote_code_model=True,
|
| 84 |
+
save_compressed=True,
|
| 85 |
+
output_dir=SAVE_DIR,
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
print("========== SAMPLE GENERATION ==============")
|
| 89 |
+
SAMPLE_INPUT = ["I love quantization because"]
|
| 90 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 91 |
+
inputs = tokenizer(SAMPLE_INPUT, return_tensors="pt", padding=True).to(model.device)
|
| 92 |
+
output = model.generate(**inputs, max_length=50)
|
| 93 |
+
text_output = tokenizer.batch_decode(output)
|
| 94 |
+
print(text_output)
|
| 95 |
+
|
| 96 |
+
```
|