Ricerca nel sito web

Come eseguire modelli linguistici di grandi dimensioni DeepSeek R1 su droplet GPU


Qui a DigitalOcean, stiamo osservando attentamente la chiusura del divario tra i Large Language Models (LLM) open source e le loro controparti commerciali e closed-source. Una delle capacità più importanti di questi modelli è il ragionamento: l'azione di pensare a qualcosa in modo logico e sensato.

Per molto tempo, i LLM sono stati molto lineari. Quando è stato richiesto, hanno fornito una risposta. Non è coinvolta alcuna metalogica, né alcuna fase in cui il modello potrebbe essere in grado di autocorreggersi se è errato. Ciò ostacola di fatto la loro capacità di ragionare, porre domande o adattarsi a problemi che potrebbero essere inerenti all’istruzione a cui stanno rispondendo. Ad esempio, con modelli a basso ragionamento, problemi matematici complessi basati sul linguaggio potrebbero essere troppo complicati da risolvere senza istruzioni esplicite e lavoro da parte degli utenti.

Inserisci l'ultima generazione di LLM di ragionamento. Introdotti dalla serie di modelli O1 di OpenAI, i modelli di ragionamento hanno preso d'assalto la comunità poiché hanno effettivamente colmato il divario tra le capacità di apprendimento umano e automatico su una varietà di compiti logici. Questi includono la codifica, la matematica e persino il ragionamento scientifico.

Come con tutti i precedenti passi avanti nello sviluppo, la comunità open source ha lavorato duramente per abbinare le funzionalità dei modelli di sorgente chiusa. Di recente, i primi modelli open source per raggiungere questo livello di ragionamento astratto, la serie di LLM DeepSeek R1, sono stati rilasciati al pubblico.

Nella prima di questa serie di articoli in 2 parti, mostreremo come eseguire questi modelli sulle GPU Droplet di DigitalOcean utilizzando Ollama. I lettori possono aspettarsi di imparare come configurare GPU Droplet, installare Ollama e iniziare a ragionare con Deepseek R1.

Prerequisiti

  • Account DigitalOcean: questo tutorial utilizzerà le goccioline GPU di DigitalOcean
  • Familiarità con la shell Bash: utilizzeremo il terminale per accedere, scaricare e utilizzare Ollama. Verranno forniti i comandi

Configurazione della droplet GPU

La prima cosa che dobbiamo fare è impostare la nostra macchina. Per iniziare, creare una nuova goccia GPU seguendo la procedura mostrata nella documentazione ufficiale di digitalocean.

Ti consigliamo di selezionare il sistema operativo "AI/ML Ready" e di utilizzare una singola GPU NVIDIA H100 per questo progetto, a meno che non intendi utilizzare il modello di parametri 671B più grande.

Una volta avviata la macchina, procedere alla sezione successiva.

Installazione di Ollama e DeepSeek R1

Per questa dimostrazione, trarremo vantaggio dall'incredibile lavoro svolto dagli sviluppatori di Ollama per portare il nostro modello online a velocità rapida. Apri una finestra della console Web utilizzando il pulsante in alto a destra della pagina dei dettagli della goccia GPU e vai alla directory di lavoro di scelta.

Una volta che sei nel luogo in cui desideri lavorare, incolla il seguente comando nel terminale:

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

Ciò eseguirà l'installazione di Ollama sulla nostra macchina. Questo processo potrebbe richiedere alcuni minuti mentre si installa. Una volta completato, tutto è pronto per partire! Non era semplice?

Ora, tutto ciò che dobbiamo fare è eseguire il comando che esegue DeepSeek R1 sul nostro computer. Ollama fornisce tutte le dimensioni del modello disponibili (parametri 1.5b, 7b, 8b, 14b, 32b, 70b e 671b), quindi consigliamo di utilizzare il modello più grande disponibile per l'esecuzione su una singola GPU, il modello 70b.

ollama run deepseek-r1:70b

Ci vorranno alcuni minuti la prima volta che viene eseguito per scaricare il modello da circa 40 GB sulla nostra macchina e caricarlo, ma da qui otterremo una finestra interattiva per chattare con il nostro modello di ragionamento open source.

Ragionare con DeepSeek R1

Come accennato all'inizio di questo articolo, R1 è in grado di gestire compiti complessi legati alla matematica, alla programmazione e persino al ragionamento scientifico. Un modello di ragionamento è una struttura o un insieme di principi che guidano il modo in cui un sistema di intelligenza artificiale ragiona, prende decisioni e risolve i problemi. Delinea gli algoritmi, le tecniche e le euristiche che consentono all'intelligenza artificiale di trarre inferenze, trarre conclusioni dalle informazioni disponibili e generare soluzioni a compiti complessi. Lo fa utilizzando la natura iterativa dei modelli GPT con ragionamento metalogico per comprendere meglio e dedurre soluzioni al problema proposto.

Proviamo un esempio di problema di matematica (fonte) e vediamo come il modello motiva la risposta:

## 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}}
\]

Osserva attentamente il modo in cui il modello ha ragionato sulla risposta a questa domanda. Innanzitutto ha determinato i parametri per risolvere il problema: trovare il peso totale dei vasi da fiori e del materiale di imballaggio. Ha poi ribadito i fatti del problema e ha mostrato il proprio lavoro ragionando individualmente sul peso totale dei vasi da fiori e dei materiali di imballaggio. Ha quindi combinato questi valori e poi ha confrontato i due valori per ottenere la risposta corretta: no.

Ora, diamo un'occhiata a un esempio di codifica:

## 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.

Ancora una volta, questo è un esempio molto significativo delle capacità di ragionamento del modello. Nella replica ha anzitutto fornito una risposta sufficiente. Proseguendo, si è argomentato che la risposta potrebbe non prendere in considerazione tutti i possibili casi limite per l'utente, come la conversione di tutti i file in una directory. Per migliorare questo problema, ha fornito un'altra soluzione funzionante che risolve meglio ogni potenziale problema. Ha poi esposto dettagliatamente tali considerazioni per concludere la risposta. Nel complesso, si tratta di una soluzione davvero impressionante e completa che imita quasi il ragionamento di un attore umano.

Sulla base di queste risposte, ti consigliamo di provare tutti i tipi di domande stimolanti con R1. Il modello è incredibilmente robusto, soprattutto a livello di parametro 60b e oltre.

Pensieri di chiusura

In questo articolo, abbiamo mostrato come eseguire DeepSeek R1 utilizzando le GPU Droplet di DigitalOcean con Ollama. Come abbiamo visto sopra, questo ci fornisce un meccanismo di ragionamento veloce e potente che ci aiuta in una varietà di compiti, tra cui la programmazione e la matematica. Siamo rimasti molto colpiti da questi modelli e li utilizzeremo sicuramente per facilitare i progetti ove possibile.

Torna presto per leggere la seconda parte di questa serie, in cui approfondiremo l'architettura di R1, approfondiremo il modo in cui è stato eseguito l'addestramento del modello e impareremo cosa rende il ragionamento del modello così potente.