首頁 > 科技週邊 > 人工智慧 > 在Databricks上部署DeepSeek R1:逐步指南

在Databricks上部署DeepSeek R1:逐步指南

Jennifer Aniston
發布: 2025-02-28 16:33:10
原創
835 人瀏覽過

>在Databricks上部署DeepSeek R1模型:逐步指南

流行的數據工程平台 databricks越來越多地用於AI和機器學習任務。 該教程通過在Databricks上部署分佈式DeepSeek R1模型來指導您,這是一種強大的大型語言模型,通常是本地部署的優先使用。 這避免將數據發送到外部服務器。 要深入了解DeepSeek R1的功能和比較,請參見DeepSeek-R1:功能,比較,蒸餾模型和更多博客。

本指南涵蓋了帳戶設置,使用UI的模型註冊以及通過操場和本地捲曲命令訪問。 Databricks的新手? Databricks課程簡介提供了Databricks Lakehouse平台及其數據管理功能的全面概述。 要更深入地了解Databricks中的數據管理,請考慮Databricks課程中的數據管理。

註冊DeepSeek R1模型>

    >
  1. >啟動筆記本:創建您的數據鏈球工作空間後,單擊“ new”,然後選擇筆記本。

Deploying DeepSeek R1 on Databricks: A Step-by-Step Guide

    >
  1. >安裝軟件包:安裝必要的python庫:
%%capture
!pip install torch transformers mlflow accelerate torchvision
%restart_python
登入後複製
登入後複製
  1. 負載模型和代幣器:從擁抱面上加載DeepSeek R1型號和令牌,>
import pandas as pd
import mlflow
import mlflow.transformers
import torch
from mlflow.models.signature import infer_signature
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig, pipeline

model_name = "deepseek-ai/DeepSeek-R1-Distill-Llama-8B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
config = AutoConfig.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, config=config, torch_dtype=torch.float16)
登入後複製

Deploying DeepSeek R1 on Databricks: A Step-by-Step Guide

    >>>測試模型:
  1. 使用樣本提示進行測試,並生成用於模型註冊的簽名:
預期輸出(可能會稍有變化):
text_generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
example_prompt = "How does a computer work?"
example_inputs = pd.DataFrame({"inputs": [example_prompt]})
example_outputs = text_generator(example_prompt, max_length=200)
signature = infer_signature(example_inputs, example_outputs)
print(example_outputs)
登入後複製

<code>[{'generated_text': "How does a computer work? What is the computer? What is the computer used for? What is the computer used for in real life?\n\nI need to answer this question, but I need to do it step by step. I need to start with the very basic level and build up from there. I need to make sure I understand each concept before moving on. I need to use a lot of examples to explain each idea. I need to write my thoughts as if I'm explaining them to someone else, but I need to make sure I understand how to structure the answer properly.\n\nOkay, let's start with the basic level. What is a computer? It's an electronic device, right? And it has a central processing unit (CPU) that does the processing. But I think the central processing unit is more efficient, so maybe it's the CPU. Then, it has memory and storage. I remember that memory is like RAM and storage is like ROM. But wait, I think"}]</code>
登入後複製
    conda環境:
  1. 定義一個conda環境:
conda_env = {
    "name": "mlflow-env",
    "channels": ["defaults", "conda-forge"],
    "dependencies": [
        "python=3.11",
        "pip",
        {"pip": ["mlflow", "transformers", "accelerate", "torch", "torchvision"]}
    ]
}
登入後複製
    註冊模型:
  1. 使用註冊模型: mlflow.transformers.log_model
with mlflow.start_run() as run:
    mlflow.transformers.log_model(
        transformers_model=text_generator,
        artifact_path="deepseek_model",
        signature=signature,
        input_example=example_inputs,
        registered_model_name="deepseek_r1_llama_8b",
        conda_env=conda_env
    )
登入後複製

Deploying DeepSeek R1 on Databricks: A Step-by-Step Guide

部署DeepSeek R1

    >
  1. >導航到模型:

    在databricks儀表板中,轉到“模型”選項卡。

    >
  2. 使用模型:
  3. 選擇您的模型,然後單擊“使用此模型”。

    1. 配置端點:命名您的端點,選擇計算選項,設置並發性,然後單擊“創建”。

    Deploying DeepSeek R1 on Databricks: A Step-by-Step Guide

    Deploying DeepSeek R1 on Databricks: A Step-by-Step Guide

    有關自定義數據集上的微調,請參閱微調DeepSeek R1教程。

    >訪問已部署的模型

    >

      > databricks Playground:
    1. 直接在Databricks Playground中進行測試。

    Deploying DeepSeek R1 on Databricks: A Step-by-Step Guide

      curl命令:生成數據鏈球api鍵(設置&gt; developer),將其設置為環境變量(
    1. ),然後使用curl:> $DATABRICKS_TOKEN
    %%capture
    !pip install torch transformers mlflow accelerate torchvision
    %restart_python
    登入後複製
    登入後複製

    Deploying DeepSeek R1 on Databricks: A Step-by-Step Guide

    有關DeepSeek R1 vs. V3的信息,請參見DeepSeek R1 vs V3博客。 LLM的新手? Python課程中LLMS的介紹是一個很棒的起點。 請記住,儘管CPU部署是可能的,但可能會慢。

    >

    以上是在Databricks上部署DeepSeek R1:逐步指南的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板