# Fortgesetztes Vortraining

* Der [Textvervollständigungs-Notebook](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Mistral_\(7B\)-Text_Completion.ipynb) ist für fortgesetztes Pretraining/rohen Text.
* Der [Notebook für fortgesetztes Pretraining](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Mistral_v0.3_\(7B\)-CPT.ipynb) ist zum Erlernen einer anderen Sprache.

Sie können mehr über fortgesetztes Pretraining und unsere Veröffentlichung in unserem [Blogbeitrag](https://unsloth.ai/blog/contpretraining).

## Was ist fortgesetztes Pretraining?

Fortgesetztes oder kontinuierliches Pretraining (CPT) ist notwendig, um das Sprachmodell in neue Wissensdomänen oder aus Verteilungsdomänen „zu steuern“. Basismodelle wie Llama-3 8b oder Mistral 7b werden zunächst auf gigantischen Datensätzen von Billionen Token vortrainiert (Llama-3 z. B. auf 15 Billionen).

Aber manchmal wurden diese Modelle nicht gut auf andere Sprachen oder textspezifische Bereiche wie Recht, Medizin oder andere Gebiete trainiert. Daher ist fortgesetztes Pretraining (CPT) notwendig, damit das Sprachmodell neue Tokens oder Datensätze lernt.

## Erweiterte Funktionen:

### Laden von LoRA-Adaptern zum fortgesetzten Finetuning

Wenn Sie einen LoRA-Adapter über Unsloth gespeichert haben, können Sie das Training auch mit Ihren LoRA-Gewichten fortsetzen. Der Optimizer-Zustand wird dabei ebenfalls zurückgesetzt. Um sogar Optimizer-Zustände zu laden, um das Finetuning fortzusetzen, siehe den nächsten Abschnitt.

```python
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "LORA_MODEL_NAME",
    max_seq_length = max_seq_length,
    dtype = dtype,
    load_in_4bit = load_in_4bit,
)
trainer = Trainer(...)
trainer.train()
```

### Fortgesetztes Pretraining & Finetuning des `lm_head` als auch `embed_tokens` Matrizen

Hinzufügen `lm_head` als auch `embed_tokens`. Für Colab kann es vorkommen, dass für Llama-3 8b nicht genügend Arbeitsspeicher vorhanden ist. Falls ja, fügen Sie einfach hinzu `lm_head`.

```python
model = FastLanguageModel.get_peft_model(
    model,
    r = 16,
    target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
                      "gate_proj", "up_proj", "down_proj",
                      "lm_head", "embed_tokens",],
    lora_alpha = 16,
)
```

Verwenden Sie dann 2 verschiedene Lernraten - eine 2-10x kleinere für das `lm_head` oder `embed_tokens` wie folgt:

```python
from unsloth import UnslothTrainer, UnslothTrainingArguments

trainer = UnslothTrainer(
    ....
    args = UnslothTrainingArguments(
        ....
        learning_rate = 5e-5,
        embedding_learning_rate = 5e-6, # 2-10x kleiner als learning_rate
    ),
)
```


---

# Agent Instructions: 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://unsloth.ai/docs/de/grundlagen/continued-pretraining.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.
