> 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

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

Beste Codegenerierung ihrer Klasse mit DeepSeek Coder-Modellen.

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

## Mieten auf CLORE.AI

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

### Zugriff auf Ihren Server

* Verbindungsdetails finden Sie in **Meine Bestellungen**
* Webschnittstellen: Verwenden Sie die HTTP-Port-URL
* SSH: `ssh -p <port> root@<proxy-address>`

## Was ist DeepSeek Coder?

DeepSeek Coder bietet:

* Modernste Codegenerierung
* 338 Programmiersprachen
* Fill-in-the-middle-Unterstützung
* Repository-übergreifendes Verständnis

## Modellvarianten

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

## Schnelle Bereitstellung

**Docker-Image:**

```
pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime
```

**Ports:**

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

**Befehl:**

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

## Zugriff auf Ihren Dienst

Nach der Bereitstellung finden Sie Ihre `http_pub` URL in **Meine Bestellungen**:

1. Gehen Sie zur **Meine Bestellungen** Seite
2. Klicken Sie auf Ihre Bestellung
3. Finden Sie die `http_pub` URL (z. B., `abc123.clorecloud.net`)

Verwenden Sie `https://IHRE_HTTP_PUB_URL` anstelle von `localhost` in den Beispielen unten.

## 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)
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
- Retry-Logik mit exponentiellem Backoff
- Anfrage-/Antwort-Protokollierung
"""}
]

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))
```

## Fill-in-the-Middle (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 Mittelwert, Median und Std 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

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 threadsicheren 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 erfahrener Programmierer."},
        {"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}
````

Fokus auf:

1. Leistung
2. Lesbarkeit
3. Best Practices """} ]

````

## Bugfixing

```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="Prompt", lines=5, placeholder="Beschreibe den Code, den du brauchst..."),
        gr.Slider(0.1, 1.0, value=0.2, label="Temperature"),
        gr.Slider(256, 2048, value=1024, step=128, label="Max Tokens")
    ],
    outputs=gr.Code(language="python", label="Generierter Code"),
    title="DeepSeek Coder"
)

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

## Leistung

| Modell           | GPU      | Tokens/sec |
| ---------------- | -------- | ---------- |
| 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%     | Ausgezeichnet |
| CodeLlama-34B      | 53.7%     | Gut           |
| GPT-3.5-Turbo      | 72.6%     | Gut           |

## Fehlerbehebung

### Codevervollständigung funktioniert nicht

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

### Modell liefert Müll

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

### Langsame Inferenz

* Verwende vLLM für 5–10x Geschwindigkeit
* Aktivieren Sie `torch.compile()` für transformers
* Verwende quantisiertes Modell für große Varianten

### Importfehler

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

## Kostenabschätzung

Typische CLORE.AI-Marktplatztarife (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           |

*Preise variieren je nach Anbieter und Nachfrage. Prüfen Sie* [*CLORE.AI Marketplace*](https://clore.ai/marketplace) *auf aktuelle Preise.*

**Geld sparen:**

* Verwenden Sie **Spot** Markt für flexible Workloads (oft 30–50% günstiger)
* Bezahlen mit **CLORE** Token
* Preise bei verschiedenen Anbietern vergleichen

## Nächste Schritte

* [DeepSeek-V3](/guides/guides_v2-de/sprachmodelle/deepseek-v3.md) - Neuestes DeepSeek-Flaggschiffmodell
* [CodeLlama](/guides/guides_v2-de/sprachmodelle/codellama.md) - Alternatives Codemodell
* [Qwen2.5-Coder](/guides/guides_v2-de/sprachmodelle/qwen25.md) - Alibabas Codemodell
* [vLLM](/guides/guides_v2-de/sprachmodelle/vllm.md) - Produktionsbereitstellung


---

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

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

The question should be specific, self-contained, and written in natural language.
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.
