Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mps support #22

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add an util function to detect platflorm and suitable dtype
  • Loading branch information
Fodark committed Mar 13, 2024
commit 494e622544b7aefd5634fdc72878a0289d4e548f
21 changes: 21 additions & 0 deletions deepseek_vl/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@
from deepseek_vl.models import MultiModalityCausalLM, VLChatProcessor


def get_device_and_dtype():
"""
Get the device and dtype for the model.
"""

if torch.cuda.is_available():
print("Using CUDA and BFloat16")
device = torch.device("cuda")
dtype = torch.bfloat16
elif torch.backends.mps.is_available():
print("Using MPS and FP16")
device = torch.device("mps")
dtype = torch.float16
else:
print("Using CPU and FP32")
device = torch.device("cpu")
dtype = torch.float32

return device, dtype


def load_pretrained_model(model_path: str):
vl_chat_processor: VLChatProcessor = VLChatProcessor.from_pretrained(model_path)
tokenizer = vl_chat_processor.tokenizer
Expand Down