Rumah >Peranti teknologi >AI >Menggunakan DeepSeek R1 di Databricks: Panduan Langkah demi Langkah
Menggunakan Model DeepSeek R1 pada Databricks: Panduan Langkah demi Langkah
Databricks, platform kejuruteraan data yang popular, semakin digunakan untuk tugas pembelajaran AI dan mesin. Tutorial ini membimbing anda melalui penggunaan model DeepSeek R1 yang diedarkan pada Databricks, model bahasa besar yang kuat sering disukai untuk penggunaan premis. Ini mengelakkan menghantar data ke pelayan luaran. Untuk menyelam yang lebih mendalam ke dalam ciri dan perbandingan Deepseek R1, lihat DeepSeek-R1: Ciri-ciri, Perbandingan, Model Sulingan & Lebih Banyak Blog.
Panduan ini merangkumi persediaan akaun, pendaftaran model menggunakan UI, dan akses melalui taman permainan dan perintah curl tempatan. Baru untuk pangkalan data? Kursus Pengenalan kepada Databricks memberikan gambaran menyeluruh mengenai platform Databricks Lakehouse dan keupayaan pengurusan datanya. Untuk pemahaman yang lebih mendalam tentang pengurusan data dalam pangkalan data, pertimbangkan pengurusan data dalam kursus Databricks.
Mendaftarkan model DeepSeek R1
<code class="language-python">%%capture !pip install torch transformers mlflow accelerate torchvision %restart_python</code>
<code class="language-python">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)</code>
<code class="language-python">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>
<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>
<code class="language-python">conda_env = { "name": "mlflow-env", "channels": ["defaults", "conda-forge"], "dependencies": [ "python=3.11", "pip", {"pip": ["mlflow", "transformers", "accelerate", "torch", "torchvision"]} ] }</code>
mlflow.transformers.log_model
<code class="language-python">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 )</code>
Menggunakan DeepSeek R1
Untuk penalaan halus pada dataset tersuai, rujuk tutorial DeepSeek R1 yang baik.
Mengakses model yang digunakan
$DATABRICKS_TOKEN
<code class="language-python">%%capture !pip install torch transformers mlflow accelerate torchvision %restart_python</code>
Untuk maklumat mengenai DeepSeek R1 vs V3, lihat blog DeepSeek R1 vs V3. Baru ke LLMS? Pengenalan kepada LLMS dalam kursus Python adalah titik permulaan yang hebat. Ingatlah bahawa sementara penggunaan CPU mungkin, mungkin lebih perlahan.
Atas ialah kandungan terperinci Menggunakan DeepSeek R1 di Databricks: Panduan Langkah demi Langkah. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!