> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/de/grundlagen/continued-pretraining.md).

# Fortgesetztes Pretraining

Auch bekannt als fortgesetzte Feinabstimmung. Unsloth ermöglicht fortlaufendes Pretraining, damit ein Modell eine neue Sprache lernen kann.

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

Mehr über fortgesetztes Vortraining und unsere Veröffentlichung kannst du in unserem [Blogbeitrag](https://unsloth.ai/blog/contpretraining).

## Was ist fortgesetztes Vortraining?

Fortgesetztes oder kontinuierliches Vortraining (CPT) ist notwendig, um das Sprachmodell zu „steuern“, damit es neue Wissensdomänen oder Domänen außerhalb der Verteilung versteht. Basismodelle wie Llama-3 8B oder Mistral 7B werden zunächst auf gigantischen Datensätzen mit Billionen von Tokens vortrainiert (Llama-3 umfasst z. B. 15 Billionen).

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

## Erweiterte Funktionen:

### LoRA-Adapter für fortgesetztes Finetuning laden

Wenn du über Unsloth einen LoRA-Adapter gespeichert hast, kannst du das Training auch mit deinen LoRA-Gewichten fortsetzen. Der Zustand des Optimierers wird ebenfalls zurückgesetzt. Um auch die Optimiererzustände zu laden und 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 Vortraining & Finetuning des `lm_head` und `embed_tokens` Matrizen

Fügen Sie `lm_head` und `embed_tokens`. Für Colab kann bei Llama-3 8B manchmal der Speicher ausgehen. Wenn das passiert, füge einfach `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,
)
```

Verwende dann 2 verschiedene Lernraten – eine 2- bis 10-mal kleinere für die `lm_head` oder `embed_tokens` so:

```python
from unsloth import UnslothTrainer, UnslothTrainingArguments

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


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://unsloth.ai/docs/de/grundlagen/continued-pretraining.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
