deepseek-ai / deepseek-ai/DeepSeek-OCR

[Important] Type Inconsistency (with Solution)

Open
#101 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
23.9k
Forks
2.2k
PR merge metrics
No merged PRs in 30d

Description

Original code in `modelling_deepseekocr.py` is like

inputs_embeds[idx].masked_scatter_(images_seq_mask[idx].unsqueeze(-1).cuda(), images_in_this_batch)

But it only applies for bfloat16 and does not work for quantized veresions for example when using with

bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16
)
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = DeepseekOCRForCausalLM.from_pretrained(
pretrained_model_name_or_path=model_name,
quantization_config=bnb_config,
trust_remote_code=True,
use_safetensors=True
)

One solution is to replace the line with:
"""
mask = images_seq_mask[idx].unsqueeze(-1).to(device=inputs_embeds.device).bool()
source = images_in_this_batch.to(device=inputs_embeds.device, dtype=inputs_embeds.dtype)
inputs_embeds[idx].masked_scatter_(mask, source)
"""

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.