ウェブサイト検索

GPUドロップレットでDeepSeek R1大規模言語モデルを実行する方法


デジタルオーシャンでは、オープンソースの大規模言語モデル(LLM)と商業用のクローズドソースのモデルとの間のギャップが縮まる様子を注意深く見守っています。これらのモデルの最も重要な能力の一つは、推論 - つまり、何かを論理的かつ理にかなった方法で考える行動です。

長い間、LLMは非常に直線的でした。プロンプトが与えられると、彼らは答えを提供しました。そこにはメタ論理が関与しておらず、モデルが間違っている場合に自己修正する可能性がある段階もありません。このことは、彼らが推論を行ったり、質問したり、指示に固有の問題に適応したりする能力を実質的に妨げます。例えば、推論能力の低いモデルでは、複雑な言語に基づく数学の問題は、明示的な指示やユーザー側の作業なしには解くのが難しすぎるかもしれません。

最新世代の推論LLMが登場しました。OpenAIのO1モデルシリーズによってもたらされた推論モデルは、さまざまな論理タスクにおいて人間と機械の学習能力の差を効果的に縮めたため、コミュニティを驚かせています。これには、コーディング、数学、さらには科学的推論が含まれます。

これまでのすべての開発の進展と同様に、オープンソースコミュニティはクローズドソースモデルの能力に追いつくために懸命に働いてきました。最近、このレベルの抽象的推論を達成した最初のオープンソースモデル、Deepseek R1シリーズのLLMが一般に公開されました。

この2部構成の記事の第一部では、Ollamaを使用してDigitalOceanのGPU Droplet上でこれらのモデルを実行する方法を示します。読者は、GPU Dropletの設定方法、Ollamaのインストール方法、そしてDeepseek R1を使って推論を始める方法を学ぶことができるでしょう。

前提条件

  • DigitalOceanアカウント:このチュートリアルではDigitalOceanのGPUドロップレットを使用します
  • Bashシェルの親しみ: 私たちはターミナルを使用してOllamaにアクセスし、ダウンロードし、使用します。コマンドは提供されます。

GPUドロップレットの設定

最初に私たちがやるべきことは、マシンを設定することです。まず、公式のDigitalOceanドキュメントに示された手順に従って、新しいGPU Dropletを作成します。

このプロジェクトには「AI/ML Ready」オペレーティングシステムを選択し、NVIDIA H100 GPUを一つ使用することを推奨します。ただし、671Bパラメータの最大モデルを使用するつもりでない場合は除きます。

マシンが起動したら、次のセクションに進んでください。

Ollama と DeepSeek R1 のインストール

このデモンストレーションでは、Ollamaの開発者たちが行った素晴らしい作業を利用して、私たちのモデルを迅速にオンラインにします。GPUドロップレットの詳細ページの右上にあるボタンを使用してWebコンソールウィンドウを開き、選択した作業ディレクトリに移動してください。

働きたい場所に入ったら、次のコマンドをターミナルに貼り付けてください:

curl -fsSL https://ollama.com/install.sh | sh

これにより、Ollamaのインストールが私たちの機械で実行されます。このプロセスは、インストール中に数分かかる場合があります。完了したら、すべての準備は整います!簡単ではありませんでしたか?

さて、私たちがする必要があるのは、私たちのマシンでDeepSeek R1を実行するコマンドを実行することだけです。Ollamaはすべての利用可能なモデルサイズ(1.5b、7b、8b、14b、32b、70b、および671bパラメータ)を提供しているので、単一のGPUで実行するために利用可能な最大のモデルである70bモデルを使用することをお勧めします。

ollama run deepseek-r1:70b

最初に実行する際には、約40GBのモデルを私たちのマシンにダウンロードして読み込むのに数分かかりますが、ここからはオープンソースの推論モデルと対話できるインタラクティブなウィンドウが得られます。

DeepSeek R1による推論

この記事の冒頭で述べたように、R1は数学、コーディング、さらには科学的推論に関連する複雑なタスクを処理する能力があります。推論モデルは、AIシステムがどのように推論し、意思決定を行い、問題を解決するのかを導く枠組みまたは原則のセットです。それは、AIが推論を引き出し、利用可能な情報から結論を導き出し、複雑なタスクに対する解決策を生成するために必要なアルゴリズム、技術、ヒューリスティックスを概説します。これは、提案された問題に対する解決策をより良く理解し推測するために、メタロジック推論を用いて、GPTモデルの反復的な性質を活用することで実現します。

サンプルの数学の問題を試してみましょう(ソース)、そしてモデルがどのように回答を導き出すかを見てみましょう:

## input
Answer this question: A package that is heavier than 11 lbs and 8 oz will have a label that says “heavy” on it. Gloria packed 6 flowerpots to send to her customers. Each of the flowerpots weighs 1 lb and 12 oz. The packing material weighs 5 oz. Will her package be labeled as “heavy”?
## output
<think>
First, I need to determine the total weight of Gloria's package to see if it exceeds the threshold for
being labeled as "heavy."

Gloria has packed 6 flowerpots, each weighing 1 pound and 12 ounces. Additionally, there is packing
material that weighs 5 ounces.

I'll start by calculating the total weight of all the flowerpots. Since each pot is 1 lb 12 oz, multiplying
this by 6 gives:
6 pots × (1 lb + 12 oz) = 6 lbs and 72 oz.

Next, I need to convert the 72 ounces into pounds because the threshold is given in pounds and ounces.
Knowing that 16 ounces make a pound, I divide 72 by 16:
72 oz ÷ 16 oz/lb = 4.5 lb.

So, the flowerpots weigh a total of 6 lbs + 4.5 lbs = 10.5 lbs.

Now, adding the weight of the packing material, which is 5 ounces. To maintain consistent units, I convert
5 ounces to pounds:
5 oz ÷ 16 oz/lb ≈ 0.3125 lb.

Adding this to the flowerpots' total weight:
10.5 lbs + 0.3125 lbs = 10.8125 lbs.

Finally, comparing the total package weight of approximately 10.81 lbs to the 11 lbs and 8 oz threshold,
which is equivalent to 11.5 lbs (since 8 oz = 0.5 lb). Since 10.81 lbs is less than 11.5 lbs, the package
will not be labeled as "heavy."
</think>

**Solution:**

To determine if Gloria's package will be labeled as “heavy,” we need to calculate its total weight and
compare it to the threshold of **11 lbs and 8 oz** (which is equivalent to **11.5 lbs**).

1. **Calculate the Weight of the Flowerpots:**
   
   - Each flowerpot weighs **1 lb and 12 oz**.
   - Convert **12 oz** to pounds:
\[
12\ \text{oz} = \frac{12}{16}\ \text{lbs} = 0.75\ \text{lbs}
\]

- So, each flowerpot weighs **1.75 lbs**.

- Gloria packed **6 flowerpots**, so:
\[
6 \times 1.75\ \text{lbs} = 10.5\ \text{lbs}
\]

2. **Add the Weight of Packing Material:**

- The packing material weighs **5 oz**.
- Convert **5 oz** to pounds:
\[
5\ \text{oz} = \frac{5}{16}\ \text{lbs} \approx 0.3125\ \text{lbs}
\]

- Total weight of the package:
\[
10.5\ \text{lbs} + 0.3125\ \text{lbs} = 10.8125\ \text{lbs}
\]

3. **Compare with the Threshold:**

- The threshold for a “heavy” label is **11 lbs and 8 oz**, which is **11.5 lbs**.

- Since **10.8125 lbs < 11.5 lbs**, the package does **not** meet the criteria for being labeled as
“heavy.”

**Final Answer:**

\[
\boxed{\text{No}}
\]

この質問に対するモデルの回答の仕方をよく見てください。最初に、その質問を解決するためのパラメータを決定しました:花の鉢と梱包材の総重量を求めることです。その後、問題の事実を繰り返し、花の鉢と梱包材の総重量を個別に推論する作業を示しました。そして、それらの値を組み合わせ、2つの値を比較して正しい答えを得ました:いいえ。

さあ、コーディングの例を見てみましょう:

## input
How can i write a Python function that converts wav files to mp3s?

## output
Okay, so I want to create a Python function that converts WAV files to MP3s. Hmm, where do I start? Well, I
know that WAV and MP3 are both audio formats, but they're different in terms of compression and quality.
WAV is uncompressed, which makes the files larger, while MP3 is compressed, making the files smaller but
with some loss in quality.

First, I need to figure out how to read a WAV file in Python. I've heard about libraries like `wave` or
`soundfile`, but I'm not sure if they can help me convert formats. Maybe those are more for manipulating
audio data rather than converting formats.

Then there's the conversion part. How do I actually convert a WAV file into an MP3? It seems like I might
need some external tool or library that handles the encoding. Oh, right! I think `ffmpeg` is a powerful
tool for audio and video processing. Maybe I can use it within Python.

So, perhaps I can write a function that uses `ffmpeg` to convert the WAV file to MP3. But how do I
interface with `ffmpeg` from Python? I recall there's a library called `subprocess` that allows you to run
shell commands from Python. That could work.

Wait, but is there a more direct way without using shell commands? Maybe there are pure Python libraries
for converting audio formats. I did some searching and found `pydub`. It seems like `pydub` can handle
format conversions and uses `ffmpeg` under the hood. That might be easier to use than dealing with
`subprocess` directly.

Alright, so I'll go with `pydub`. First, I need to install it using pip:

pip install pydub


But wait, does `pydub` require `ffmpeg` to be installed on my system? Yes, it does. So I need to make sure
that `ffmpeg` is installed and accessible from the command line.

Once that's set up, I can write a function that takes a WAV file path as input and outputs an MP3 file. Let
me sketch this out:

1. Import the necessary modules.
2. Define a function called `convert_wav_to_mp3`.
3. Use `pydub.AudioSegment` to read the WAV file.
4. Export the audio segment to MP3 format.

But I should also handle exceptions, like if the input file doesn't exist or if there's an error during
conversion. Maybe add some try-except blocks for better error handling.

Let me think about potential issues:
- What if the output path already exists? Should I overwrite it or raise an error?
- How do I handle different bitrates or quality settings in MP3?
- Are there any specific parameters I need to set for the conversion?

For now, I'll keep it simple and focus on a basic conversion. I can always add more features later.

So, putting it all together, here's what my function might look like:


from pydub import AudioSegment

def convert_wav_to_mp3(wav_file_path, mp3_file_path):
  try:
Load the WAV file
    sound = AudioSegment.from_wav(wav_file_path)
 
Export to MP3
   sound.export(mp3_file_path, format="mp3")
 
   print("Conversion successful!")
  except Exception as e:
    print(f"An error occurred: {e}")

I should test this function with a sample WAV file to see if it works. If it does, great! I can then think
about adding more features like handling multiple files or different quality settings.

Wait, but what if the user wants to convert all WAV files in a directory? Maybe I can modify the function
to accept a list of file paths or even search for WAV files recursively. That would make the function more
versatile.

Also, considering performance, converting large numbers of files might take some time. Maybe adding
progress indicators or parallel processing could improve the user experience, but that's probably beyond
the scope of this initial implementation.

In summary, to write a Python function that converts WAV files to MP3s:
1. Use `pydub` as it simplifies the conversion process using `ffmpeg`.
2. Ensure `ffmpeg` is installed and accessible.
3. Write a function that imports the WAV file and exports it in MP3 format.
4. Add error handling for potential issues like missing files or conversion errors.

I think this approach should work well for my needs, but I'll need to test it thoroughly to make sure there
are no unexpected issues.
</think>

To convert WAV files to MP3s using Python, you can utilize the `pydub` library, which simplifies audio
format conversions by leveraging `ffmpeg`. Below is a step-by-step guide and code implementation:

**Step 1: Install Required Libraries**

First, install `pydub` using pip. Note that `pydub` requires `ffmpeg` to be installed on your system.

pip install pydub

Ensure `ffmpeg` is accessible from the command line.

**Step 2: Implement the Conversion Function**

Here's a Python function that converts a WAV file to MP3:

from pydub import AudioSegment

def convert_wav_to_mp3(wav_file_path, mp3_file_path):
#Converts a WAV file to an MP3 file.

#Args:
#wav_file_path (str): Path to the input WAV file.
#mp3_file_path (str): Desired path for the output MP3 file.
#"""
  try:
Load the WAV file
    sound = AudioSegment.from_wav(wav_file_path)
 
Export to MP3 format
    sound.export(mp3_file_path, format="mp3")
 
print("Conversion successful!")
  except Exception as e:
    print(f"An error occurred during conversion: {e}")

**Step 3: Example Usage**

To use the function:
Example usage
convert_wav_to_mp3("input.wav", "output.mp3")

This will convert `input.wav` to `output.mp3`.

**Additional Considerations:**

1. **Error Handling**: The function includes basic error handling. Depending on your needs, you can extend
it by handling specific exceptions.

2. **Multiple Files**: To process multiple WAV files, modify the function to accept a list of file paths or
iterate through a directory.

3. **Quality Settings**: `pydub` allows specifying parameters like bitrate. You can enhance the function to
accept such options.

4. **Performance**: For large-scale conversions, consider adding progress indicators or parallel processing
for efficiency.

This implementation provides a robust foundation for converting WAV files to MP3s using Python.

再び、これはモデルの推論能力を示す非常に示唆に富んだ例です。応答では、最初に十分な回答を提供しました。その後、ユーザーのすべての可能性のあるエッジケースを考慮していないかもしれないという推論を行い、ディレクトリ内のすべてのファイルを変換する場合などを挙げました。これを改善するために、あらゆる潜在的な問題をよりよく解決する別の作動するソリューションを提供しました。そして、これらの考慮点について詳細に説明し、応答を締めくくりました。全体として、これは人間の行為者の推論をほぼ模倣する非常に印象的で包括的なソリューションです。

これらの反応に基づいて、R1にさまざまな挑戦的な質問を試すことをお勧めします。このモデルは非常に堅牢であり、特に60bパラメータレベル以上での性能が優れています。

締めくくりの考え

この記事では、Ollamaを使用してDigitalOceanのGPU DropletsでDeepSeek R1を実行する方法を示しました。上で見たように、これはプログラミングや数学を含むさまざまなタスクを支援するための高速で強力な推論メカニズムを提供します。私たちはこれらのモデルに非常に感銘を受けており、できる限りプロジェクトを促進するためにそれらを使用するつもりです。

このシリーズのパート2では、R1のアーキテクチャについてさらに掘り下げ、モデルのトレーニング方法について詳しく説明し、モデルの推論がなぜそれほど強力なのかを学ぶ予定ですので、しばらくお待ちください。

関連記事: