Text Generation
Transformers
Safetensors
qwen3
feature-extraction
conversational
custom_code
text-generation-inference
Instructions to use nvidia/Efficient-DLM-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nvidia/Efficient-DLM-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="nvidia/Efficient-DLM-4B", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("nvidia/Efficient-DLM-4B", trust_remote_code=True) model = AutoModel.from_pretrained("nvidia/Efficient-DLM-4B", 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 nvidia/Efficient-DLM-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nvidia/Efficient-DLM-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Efficient-DLM-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/nvidia/Efficient-DLM-4B
- SGLang
How to use nvidia/Efficient-DLM-4B 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 "nvidia/Efficient-DLM-4B" \ --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": "nvidia/Efficient-DLM-4B", "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 "nvidia/Efficient-DLM-4B" \ --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": "nvidia/Efficient-DLM-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use nvidia/Efficient-DLM-4B with Docker Model Runner:
docker model run hf.co/nvidia/Efficient-DLM-4B
Update modeling_nvrdiff.py
Browse files- modeling_nvrdiff.py +35 -35
modeling_nvrdiff.py
CHANGED
|
@@ -486,45 +486,45 @@ class DiffEncoderModel(Qwen3PreTrainedModel, GenerationMixin):
|
|
| 486 |
logits = logits[:, :input_ids_len]
|
| 487 |
|
| 488 |
loss = None
|
| 489 |
-
if labels is not None:
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
|
| 508 |
-
|
| 509 |
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
|
| 527 |
-
|
| 528 |
|
| 529 |
return CausalLMOutputWithPast(
|
| 530 |
loss=loss if not is_teacher else logits,
|
|
|
|
| 486 |
logits = logits[:, :input_ids_len]
|
| 487 |
|
| 488 |
loss = None
|
| 489 |
+
# if labels is not None:
|
| 490 |
+
# if self.config.dlm_paradigm == 'autoregressive':
|
| 491 |
+
# shift_logits = logits[..., :-1, :].contiguous()
|
| 492 |
+
# shift_labels = labels[..., 1:].contiguous()
|
| 493 |
|
| 494 |
+
# if loss_mask is None:
|
| 495 |
+
# loss_fct = CrossEntropyLoss()
|
| 496 |
+
# shift_logits = shift_logits.view(-1, shift_logits.size(-1))
|
| 497 |
+
# shift_labels = shift_labels.view(-1)
|
| 498 |
+
# loss = loss_fct(shift_logits, shift_labels)
|
| 499 |
+
|
| 500 |
+
# else:
|
| 501 |
+
# loss_mask = loss_mask[..., 1:].contiguous()
|
| 502 |
+
|
| 503 |
+
# loss_fct = CrossEntropyLoss(reduction='none')
|
| 504 |
+
# shift_logits = shift_logits.view(-1, shift_logits.size(-1))
|
| 505 |
+
# shift_labels = shift_labels.view(-1)
|
| 506 |
+
# shift_labels = shift_labels.to(shift_logits.device)
|
| 507 |
|
| 508 |
+
# token_losses = loss_fct(shift_logits, shift_labels)
|
| 509 |
|
| 510 |
+
# loss = token_losses[loss_mask].sum() / loss_mask.sum()
|
| 511 |
+
|
| 512 |
+
# else:
|
| 513 |
+
# # Handle DREAM vs LLADA style losses
|
| 514 |
+
# if hasattr(self.config, 'dlm_type') and self.config.dlm_type == 'dream':
|
| 515 |
+
# logits = logits[..., :-1, :].contiguous()
|
| 516 |
+
# labels = labels[..., 1:].contiguous()
|
| 517 |
+
# masked_indices = masked_indices[:, 1:]
|
| 518 |
+
# p_mask = p_mask[:, 1:]
|
| 519 |
+
|
| 520 |
+
# # Calculate token-wise cross entropy loss for masked positions in B
|
| 521 |
+
# token_loss = torch.nn.functional.cross_entropy(
|
| 522 |
+
# logits[masked_indices],
|
| 523 |
+
# labels[masked_indices],
|
| 524 |
+
# reduction='none'
|
| 525 |
+
# ) / p_mask[masked_indices]
|
| 526 |
|
| 527 |
+
# loss = token_loss.sum() / masked_indices.sum()
|
| 528 |
|
| 529 |
return CausalLMOutputWithPast(
|
| 530 |
loss=loss if not is_teacher else logits,
|