> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-de/sprachmodelle/deepseek-coder.md).

# DeepSeek Coder

Best-in-class Codegenerierung mit DeepSeek Coder auf Clore.ai

{% hint style="info" %}
**Neuere Versionen verfügbar!** [**DeepSeek-R1**](/guides/guides_v2-de/sprachmodelle/deepseek-r1.md) (Schlussfolgern + Programmieren) und [**DeepSeek-V3**](/guides/guides_v2-de/sprachmodelle/deepseek-v3.md) (Allzweckmodelle) sind deutlich leistungsfähiger. Siehe auch [**Qwen2.5-Coder**](/guides/guides_v2-de/sprachmodelle/qwen25.md) für eine starke Alternative zum Programmieren.
{% endhint %}

Erstklassige Codegenerierung mit DeepSeek-Coder-Modellen.

{% hint style="success" %}
Alle Beispiele können auf GPU-Servern ausgeführt werden, die gemietet wurden über [CLORE.AI-Marktplatz](https://clore.ai/marketplace).
{% endhint %}

## Mieten auf CLORE.AI

1. Besuchen [CLORE.AI-Marktplatz](https://clore.ai/marketplace)
2. Filtern nach GPU-Typ, VRAM und Preis
3. Wähle **On-Demand** (Festpreis) oder **Spot** (Gebotspreis)
4. Konfiguriere deine Bestellung:
   * Docker-Image auswählen
   * Ports festlegen (TCP für SSH, HTTP für Web-UIs)
   * Bei Bedarf Umgebungsvariablen hinzufügen
   * Startbefehl eingeben
5. Zahlung auswählen: **CLORE**, **BTC**, oder **USDT/USDC**
6. Bestellung erstellen und auf die Bereitstellung warten

### Greife auf deinen Server zu

* Verbindungsdetails finden in **Meine Bestellungen**
* Web-Oberflächen: Verwende die HTTP-Port-URL
* SSH: `ssh -p <port> root@<proxy-address>`

## Was ist DeepSeek Coder?

DeepSeek Coder bietet:

* Hochmoderne Codegenerierung
* 338 Programmiersprachen
* Unterstützung für Fill-in-the-Middle
* Verständnis auf Repository-Ebene

## Modellvarianten

| Modell              | Parameter | VRAM  | Kontext |
| ------------------- | --------- | ----- | ------- |
| DeepSeek-Coder-1.3B | 1.3B      | 3GB   | 16K     |
| DeepSeek-Coder-6.7B | 6,7B      | 8 GB  | 16K     |
| DeepSeek-Coder-33B  | 33B       | 40 GB | 16K     |
| DeepSeek-Coder-V2   | 16B/236B  | 20GB+ | 128K    |

## Schnell bereitstellen

**Docker-Image:**

```
pytorch/pytorch:2.11.0-cuda12.8-cudnn9-runtime
```

**Ports:**

```
22/tcp
8000/http
```

**Befehl:**

```bash
pip install vllm && \\
vllm serve deepseek-ai/deepseek-coder-6.7b-instruct --port 8000
```

## Auf deinen Dienst zugreifen

Nach der Bereitstellung findest du deine `http_pub` URL in **Meine Bestellungen**:

1. Gehe zu **Meine Bestellungen** Seite
2. Klicke auf deine Bestellung
3. Finde die `http_pub` URL (z. B. `abc123.clorecloud.net`)

Verwende `https://YOUR_HTTP_PUB_URL` anstelle von `localhost` in den folgenden Beispielen.

## Verwendung von Ollama

```bash

# DeepSeek Coder ausführen
ollama run deepseek-coder

# Spezifische Größen
ollama run deepseek-coder:1.3b
ollama run deepseek-coder:6.7b
ollama run deepseek-coder:33b

# V2 (neueste Version)
ollama run deepseek-coder-v2
```

## Installation

```bash
pip install transformers accelerate torch
```

## Codegenerierung

```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_id = "deepseek-ai/deepseek-coder-6.7b-instruct"

tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True
)

messages = [
    {"role": "user", "content": """
Schreibe eine Python-Klasse für einen REST-API-Client mit:
- Unterstützung für Authentifizierung
- Wiederholungslogik mit exponentiellem Backoff
- Protokollierung von Anfrage/Antwort
"""}
]

inputs = tokenizer.apply_chat_template(
    messages,
    add_generation_prompt=True,
    return_tensors="pt"
).to("cuda")

outputs = model.generate(
    inputs,
    max_new_tokens=1024,
    temperature=0.2,
    do_sample=True
)

print(tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True))
```

## Einfügen in der Mitte (FIM)

```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_id = "deepseek-ai/deepseek-coder-6.7b-base"

tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True
)

# Fill-in-the-middle-Format
prefix = """def calculate_statistics(data):
    \"\"\"Berechne den Mittelwert, den Median und die Standardabweichung einer Liste.\"\"\"
    import statistics

    mean = statistics.mean(data)
"""

suffix = """
    return {
        'mean': mean,
        'median': median,
        'std': std
    }
"""

# FIM-Tokens
prompt = f"<｜fim▁begin｜>{prefix}<｜fim▁hole｜>{suffix}<｜fim▁end｜>"

inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=128)

print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```

## DeepSeek-Coder-V2

Die neueste und leistungsstärkste:

```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_id = "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct"

tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True
)

messages = [
    {"role": "user", "content": "Implementiere einen thread-sicheren LRU-Cache in Python"}
]

inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
outputs = model.generate(inputs, max_new_tokens=1024, temperature=0.2)
print(tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True))
```

## vLLM-Server

```bash
vllm serve deepseek-ai/deepseek-coder-6.7b-instruct \\
    --port 8000 \\
    --dtype bfloat16 \\
    --max-model-len 16384 \
    --trust-remote-code
```

### API-Nutzung

```python
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="x")

response = client.chat.completions.create(
    model="deepseek-ai/deepseek-coder-6.7b-instruct",
    messages=[
        {"role": "system", "content": "Du bist ein Experte für Programmierung."},
        {"role": "user", "content": "Schreibe einen FastAPI-WebSocket-Server"}
    ],
    temperature=0.2,
    max_tokens=1500
)

print(response.choices[0].message.content)
```

## Code-Review

````python
code_to_review = """
def process_data(data):
    result = []
    for i in range(len(data)):
        if data[i] > 0:
            result.append(data[i] * 2)
    return result
"""

messages = [
    {"role": "user", "content": f"""
Überprüfe diesen Code und schlage Verbesserungen vor:

```python
{code_to_review}
````

Konzentriere dich auf:

1. Leistung
2. Lesbarkeit
3. Bewährte Praktiken """} ]

````

## Fehlerbehebung

```python
buggy_code = """
def merge_sorted_lists(list1, list2):
    result = []
    i = j = 0
    while i < len(list1) and j < len(list2):
        if list1[i] < list2[j]:
            result.append(list1[i])
            i += 1
        else:
            result.append(list2[j])
    return result
"""

messages = [
    {"role": "user", "content": f"""
Finde und behebe den Fehler in diesem Code:

```python
{buggy_code}
````

"""} ]

````

## Gradio-Oberfläche

```python
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_id = "deepseek-ai/deepseek-coder-6.7b-instruct"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    model_id, torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=True
)

def generate_code(prompt, temperature, max_tokens):
    messages = [{"role": "user", "content": prompt}]
    inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
    outputs = model.generate(inputs, max_new_tokens=max_tokens, temperature=temperature, do_sample=True)
    return tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True)

demo = gr.Interface(
    fn=generate_code,
    inputs=[
        gr.Textbox(label="Eingabeaufforderung", lines=5, placeholder="Beschreibe den Code, den du benötigst..."),
        gr.Slider(0.1, 1.0, value=0.2, label="Temperatur"),
        gr.Slider(256, 2048, value=1024, step=128, label="Max. Tokens")
    ],
    outputs=gr.Code(language="python", label="Generierter Code"),
    DeepSeek Coder
)

demo.launch(server_name="0.0.0.0", server_port=7860)
````

## Leistung

| Modell           | GPU      | Tokens/Sek. |
| ---------------- | -------- | ----------- |
| DeepSeek-1.3B    | RTX 3060 | \~120       |
| DeepSeek-6.7B    | RTX 3090 | \~70        |
| DeepSeek-6.7B    | RTX 4090 | \~100       |
| DeepSeek-33B     | A100     | \~40        |
| DeepSeek-V2-Lite | RTX 4090 | \~50        |

## Vergleich

| Modell             | HumanEval | Codequalität |
| ------------------ | --------- | ------------ |
| DeepSeek-Coder-33B | 79.3%     | Hervorragend |
| CodeLlama-34B      | 53.7%     | Gut          |
| GPT-3.5-Turbo      | 72.6%     | Gut          |

## Fehlerbehebung

### Codevervollständigung funktioniert nicht

* Stelle sicher, dass das korrekte Prompt-Format mit `<|fim_prefix|>`, `<|fim_suffix|>`, `<|fim_middle|>`
* Setze geeignete `max_new_tokens` für die Codegenerierung

### Das Modell liefert unbrauchbare Ausgaben

* Prüfe, ob das Modell vollständig heruntergeladen ist
* Überprüfe, ob CUDA verwendet wird: `model.device`
* Versuche eine niedrigere Temperatur (0,2–0,5 für Code)

### Langsame Inferenz

* Verwende vLLM für eine 5- bis 10-fache Beschleunigung
* Aktiviere `torch.compile()` für Transformers
* Verwende ein quantisiertes Modell für große Varianten

### Importfehler

* Abhängigkeiten installieren: `pip install transformers accelerate`
* Aktualisiere PyTorch auf 2.0+

## Kostenschätzung

Übliche CLORE.AI-Marktplatzpreise (Stand 2024):

| GPU       | Stundensatz | Tagessatz | 4-Stunden-Sitzung |
| --------- | ----------- | --------- | ----------------- |
| RTX 3060  | \~$0.03     | \~$0.70   | \~$0.12           |
| RTX 3090  | \~$0.06     | \~$1.50   | \~$0.25           |
| RTX 4090  | \~$0.10     | \~$2.30   | \~$0.40           |
| A100 40GB | \~$0.17     | \~$4.00   | \~$0.70           |
| A100 80GB | \~$0.25     | \~$6.00   | \~$1.00           |

*Die Preise variieren je nach Anbieter und Nachfrage. Prüfen Sie* [*CLORE.AI-Marktplatz*](https://clore.ai/marketplace) *für aktuelle Preise.*

**Geld sparen:**

* Nutzen Sie den **Spot** Markt für unterbrechbare Arbeit — etwa ein Drittel der Server bietet Spot-Preise unter dem On-Demand-Preis (Median ca. 13 % Rabatt), der Rest ist gleichauf
* Bezahlen Sie mit **CLORE** Tokens
* Vergleichen Sie Preise zwischen verschiedenen Anbietern

## Nächste Schritte

* [DeepSeek-V3](/guides/guides_v2-de/sprachmodelle/deepseek-v3.md) - Neuestes Flaggschiffmodell von DeepSeek
* [CodeLlama](/guides/guides_v2-de/sprachmodelle/codellama.md) - Alternatives Code-Modell
* [Qwen2.5-Coder](/guides/guides_v2-de/sprachmodelle/qwen25.md) - Alibabas Code-Modell
* [vLLM](/guides/guides_v2-de/sprachmodelle/vllm.md) - Einsatz in der Produktion


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-de/sprachmodelle/deepseek-coder.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
