ウェブサイト検索

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


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

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

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

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

この2部構成の記事シリーズの第1部では、Ollamaを使用してDigitalOceanのGPUドロップレットでこれらのモデルを実行する方法を示します。読者は、GPUドロップレットの設定、Ollamaのインストール、Deepseek R1を使った推論の開始方法を学ぶことが期待できます。

前提条件

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

GPUドロップレットの設定

最初に行うべきことは、マシンをセットアップすることです。まず、公式のDigitalOceanドキュメントに示された手順に従って、新しいGPUドロップレットを作成します。

このプロジェクトには「AI/ML Ready」OSを選択し、単一のNVIDIA H100 GPUを使用することをお勧めします。ただし、671Bパラメータモデルを使用するつもりでない限り。

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

OllamaとDeepSeek R1のインストール

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

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

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ドロップレットでDeepSeek R1を実行する方法を示しました。上記のように、これはプログラミングや数学を含むさまざまなタスクを支援するための迅速で強力な推論メカニズムを提供します。私たちはこれらのモデルに非常に感銘を受けており、可能な限りプロジェクトを促進するために確実に使用するつもりです。

このシリーズのパート2を近日中にチェックしてください。そこで、R1のアーキテクチャについてさらに掘り下げ、モデルのトレーニング方法を詳しく説明し、モデルの推論がなぜそれほど強力であるかを学びます。