# embedding_metadata

key: chroma:document
string_value:
In PyTorch, the
name of a layer is defined by the name of the class attribute you give the layer. Let's define a dummy model in
PyTorch, called `SimpleModel` as follows:

```python
from torch import nn


class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.dense = nn.Linear(10, 10)
        self.intermediate = nn.Linear(10, 10)
        self.layer_norm = nn.LayerNorm(10)
```

Now we can create an instance of this model definition which will fill all weights: `dense`, `intermediate`,
`layer_norm` with random weights. We can print the model to see its architecture

```python
model = SimpleModel()

print(model)
```

This will print out the following:

```
SimpleModel(
  (dense): Linear(in_features=10, out_features=10, bias=True)
  (intermediate): Linear(in_features=10, out_features=10, bias=True)
  (layer_norm): LayerNorm((10,), eps=1e-05, elementwise_affine=True)
)
```

We can see that the layer names are defined by the name of the class attribute in PyTorch. You can print out the weight
values of a specific layer:

```python
print(model.dense.weight.data)
```

to see that the weights were randomly initialized

```
tensor([[-0.0818,  0.2207, -0.0749, -0.0030,  0.0045, -0.1569, -0.1598,  0.0212,
         -0.2077,  0.2157],
        [ 0.1044,  0.0201,  0.0990,  0.2482,  0.3116,  0.2509,  0.2866, -0.2190,
          0.2166, -0.0212],
        [-0.2000,  0.1107, -0.1999, -0.3119,  0.1559,  0.0993,  0.1776, -0.1950,
         -0.1023, -0.0447],
        [-0.0888, -0.1092,  0.2281,  0.0336,  0.1817, -0.0115,  0.2096,  0.1415,
         -0.1876, -0.2467],
        [ 0.2208, -0.2352, -0.1426, -0.2636, -0.2889, -0.2061, -0.2849, -0.0465,
          0.2577,  0.0402],
        [ 0.1502,  0.2465,  0.2566,  0.0693,  0.2352, -0.0530,  0.1859, -0.0604,
          0.2132,  0.1680],
        [ 0.1733, -0.2407, -0.1721,  0.1484,  0.0358, -0.0633, -0.0721, -0.0090,
          0.2707, -0.2509],
        [-0.1173,  0.1561,  0.2945,  0.0595, -0.1996,  0.2988, -0.0802,  0.0407,
          0.1829, -0.1568],
        [-0.1164, -0.2228, -0.0403,  0.0428,  0.1339,  0.0047,  0.1967,  0.2923,
          0.0333, -0.0536],
        [-0.1492, -0.1616,  0.1057,  0.1950, -0.2807, -0.2710, -0.1586,  0.0739,
          0.2220,  0.2358]]).


key: _node_content
string_value:
{"id_": "7a28642d-341e-4111-bd39-50aed7d0f526", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "77a5c54c-d9c7-487a-b20e-227d344691f1", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "be29d9066a3bb5441b934b61b5d05206f35f293fe5db6f3425d392ae829363e0", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "0be550a1-71ef-4912-b706-2725daa0d0f0", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "35fe84a177ab24627ab23cc00bf10ebc0454231e240d5da5eca8c92359838e28", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "8a38700d-b7ad-4fcc-a707-e53acacdc68e", "node_type": "1", "metadata": {}, "hash": "1eb8bdbc68f31d016c44971931cb0e0b77d67b3197d8f4d9164c75635f50ff1e", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 35619, "end_char_idx": 38901, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
```

In the conversion script, you should fill those randomly initialized weights with the exact weights of the
corresponding layer in the checkpoint. *E.g.*

```python
# retrieve matching layer weights, e.g. by
# recursive algorithm
layer_name = "dense"
pretrained_weight = array_of_dense_layer

model_pointer = getattr(model, "dense")

model_pointer.weight.data = torch.from_numpy(pretrained_weight)
```

While doing so, you must verify that each randomly initialized weight of your PyTorch model and its corresponding
pretrained checkpoint weight exactly match in both **shape and name**. To do so, it is **necessary** to add assert
statements for the shape and print out the names of the checkpoints weights. E.g. you should add statements like:

```python
assert (
    model_pointer.weight.shape == pretrained_weight.shape
), f"Pointer shape of random weight {model_pointer.shape} and array shape of checkpoint weight {pretrained_weight.shape} mismatched"
```

Besides, you should also print out the names of both weights to make sure they match, *e.g.*

```python
logger.info(f"Initialize PyTorch weight {layer_name} from {pretrained_weight.name}")
```

If either the shape or the name doesn't match, you probably assigned the wrong checkpoint weight to a randomly
initialized layer of the 🤗 Transformers implementation.

An incorrect shape is most likely due to an incorrect setting of the config parameters in `BrandNewBertConfig()` that
do not exactly match those that were used for the checkpoint you want to convert. However, it could also be that
PyTorch's implementation of a layer requires the weight to be transposed beforehand.

Finally, you should also check that **all** required weights are initialized and print out all checkpoint weights that
were not used for initialization to make sure the model is correctly converted. It is completely normal, that the
conversion trials fail with either a wrong shape statement or a wrong name assignment. This is most likely because either
you used incorrect parameters in `BrandNewBertConfig()`, have a wrong architecture in the 🤗 Transformers
implementation, you have a bug in the `init()` functions of one of the components of the 🤗 Transformers
implementation or you need to transpose one of the checkpoint weights.

This step should be iterated with the previous step until all weights of the checkpoint are correctly loaded in the
Transformers model. Having correctly loaded the checkpoint into the 🤗 Transformers implementation, you can then save
the model under a folder of your choice `/path/to/converted/checkpoint/folder` that should then contain both a
`pytorch_model.bin` file and a `config.json` file:

```python
model.save_pretrained("/path/to/converted/checkpoint/folder")
```

**7. Implement the forward pass**

Having managed to correctly load the pretrained weights into the 🤗 Transformers implementation, you should now make
sure that the forward pass is correctly implemented. In [Get familiar with the original repository](#3-4-run-a-pretrained-checkpoint-using-the-original-repository), you have already created a script that runs a forward
pass of the model using the original repository. Now you should write an analogous script using the 🤗 Transformers
implementation instead of the original one.


key: _node_content
string_value:
{"id_": "8a38700d-b7ad-4fcc-a707-e53acacdc68e", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "77a5c54c-d9c7-487a-b20e-227d344691f1", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "be29d9066a3bb5441b934b61b5d05206f35f293fe5db6f3425d392ae829363e0", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "7a28642d-341e-4111-bd39-50aed7d0f526", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "4e2762af4a0edf84cfa6b3c0dc4701dccb3b8b7643d28ffd1480e76980ad1441", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "390454fb-0c76-410a-9c7c-85a7334aa86c", "node_type": "1", "metadata": {}, "hash": "5334815d10b82c623f1d6822a7028d94bfda04723221d7bd352af05b898a215a", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 37147, "end_char_idx": 40667, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
However, it could also be that
PyTorch's implementation of a layer requires the weight to be transposed beforehand.

Finally, you should also check that **all** required weights are initialized and print out all checkpoint weights that
were not used for initialization to make sure the model is correctly converted. It is completely normal, that the
conversion trials fail with either a wrong shape statement or a wrong name assignment. This is most likely because either
you used incorrect parameters in `BrandNewBertConfig()`, have a wrong architecture in the 🤗 Transformers
implementation, you have a bug in the `init()` functions of one of the components of the 🤗 Transformers
implementation or you need to transpose one of the checkpoint weights.

This step should be iterated with the previous step until all weights of the checkpoint are correctly loaded in the
Transformers model. Having correctly loaded the checkpoint into the 🤗 Transformers implementation, you can then save
the model under a folder of your choice `/path/to/converted/checkpoint/folder` that should then contain both a
`pytorch_model.bin` file and a `config.json` file:

```python
model.save_pretrained("/path/to/converted/checkpoint/folder")
```

**7. Implement the forward pass**

Having managed to correctly load the pretrained weights into the 🤗 Transformers implementation, you should now make
sure that the forward pass is correctly implemented. In [Get familiar with the original repository](#3-4-run-a-pretrained-checkpoint-using-the-original-repository), you have already created a script that runs a forward
pass of the model using the original repository. Now you should write an analogous script using the 🤗 Transformers
implementation instead of the original one. It should look as follows:

```python
model = BrandNewBertModel.from_pretrained("/path/to/converted/checkpoint/folder")
input_ids = [0, 4, 4, 3, 2, 4, 1, 7, 19]
output = model(input_ids).last_hidden_states
```

It is very likely that the 🤗 Transformers implementation and the original model implementation don't give the exact
same output the very first time or that the forward pass throws an error. Don't be disappointed - it's expected! First,
you should make sure that the forward pass doesn't throw any errors. It often happens that the wrong dimensions are
used leading to a *Dimensionality mismatch* error or that the wrong data type object is used, *e.g.* `torch.long`
instead of `torch.float32`. Don't hesitate to ask the Hugging Face team for help, if you don't manage to solve
certain errors.

The final part to make sure the 🤗 Transformers implementation works correctly is to ensure that the outputs are
equivalent to a precision of `1e-3`. First, you should ensure that the output shapes are identical, *i.e.*
`outputs.shape` should yield the same value for the script of the 🤗 Transformers implementation and the original
implementation. Next, you should make sure that the output values are identical as well. This one of the most difficult
parts of adding a new model. Common mistakes why the outputs are not identical are:

- Some layers were not added, *i.e.* an *activation* layer was not added, or the residual connection was forgotten
- The word embedding matrix was not tied
- The wrong positional embeddings are used because the original implementation uses on offset
- Dropout is applied during the forward pass. To fix this make sure *model.training is False* and that no dropout
  layer is falsely activated during the forward pass, *i.e.


key: _node_content
string_value:
{"id_": "390454fb-0c76-410a-9c7c-85a7334aa86c", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "77a5c54c-d9c7-487a-b20e-227d344691f1", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "be29d9066a3bb5441b934b61b5d05206f35f293fe5db6f3425d392ae829363e0", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "8a38700d-b7ad-4fcc-a707-e53acacdc68e", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "69d972c47b9e5040ef2e1a89ffb44cb7f6d08bfdeb21d14387224a2fe3fc73ba", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "fe410dab-f86b-43bf-9b42-f39c736db694", "node_type": "1", "metadata": {}, "hash": "9b16a2c9b53d32006f57f6fadb5eb275d23da687f1e3cdb18e4db61108186782", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 39303, "end_char_idx": 42701, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
Don't be disappointed - it's expected! First,
you should make sure that the forward pass doesn't throw any errors. It often happens that the wrong dimensions are
used leading to a *Dimensionality mismatch* error or that the wrong data type object is used, *e.g.* `torch.long`
instead of `torch.float32`. Don't hesitate to ask the Hugging Face team for help, if you don't manage to solve
certain errors.

The final part to make sure the 🤗 Transformers implementation works correctly is to ensure that the outputs are
equivalent to a precision of `1e-3`. First, you should ensure that the output shapes are identical, *i.e.*
`outputs.shape` should yield the same value for the script of the 🤗 Transformers implementation and the original
implementation. Next, you should make sure that the output values are identical as well. This one of the most difficult
parts of adding a new model. Common mistakes why the outputs are not identical are:

- Some layers were not added, *i.e.* an *activation* layer was not added, or the residual connection was forgotten
- The word embedding matrix was not tied
- The wrong positional embeddings are used because the original implementation uses on offset
- Dropout is applied during the forward pass. To fix this make sure *model.training is False* and that no dropout
  layer is falsely activated during the forward pass, *i.e.* pass *self.training* to [PyTorch's functional dropout](https://pytorch.org/docs/stable/nn.functional.html?highlight=dropout#torch.nn.functional.dropout)

The best way to fix the problem is usually to look at the forward pass of the original implementation and the 🤗
Transformers implementation side-by-side and check if there are any differences. Ideally, you should debug/print out
intermediate outputs of both implementations of the forward pass to find the exact position in the network where the 🤗
Transformers implementation shows a different output than the original implementation. First, make sure that the
hard-coded `input_ids` in both scripts are identical. Next, verify that the outputs of the first transformation of
the `input_ids` (usually the word embeddings) are identical. And then work your way up to the very last layer of the
network. At some point, you will notice a difference between the two implementations, which should point you to the bug
in the 🤗 Transformers implementation. From our experience, a simple and efficient way is to add many print statements
in both the original implementation and 🤗 Transformers implementation, at the same positions in the network
respectively, and to successively remove print statements showing the same values for intermediate presentations.

When you're confident that both implementations yield the same output, verify the outputs with
`torch.allclose(original_output, output, atol=1e-3)`, you're done with the most difficult part! Congratulations - the
work left to be done should be a cakewalk 😊.

**8. Adding all necessary model tests**

At this point, you have successfully added a new model. However, it is very much possible that the model does not yet
fully comply with the required design. To make sure, the implementation is fully compatible with 🤗 Transformers, all
common tests should pass. The Cookiecutter should have automatically added a test file for your model, probably under
the same `tests/models/brand_new_bert/test_modeling_brand_new_bert.py`.


key: _node_content
string_value:
{"id_": "fe410dab-f86b-43bf-9b42-f39c736db694", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "77a5c54c-d9c7-487a-b20e-227d344691f1", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "be29d9066a3bb5441b934b61b5d05206f35f293fe5db6f3425d392ae829363e0", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "390454fb-0c76-410a-9c7c-85a7334aa86c", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "83b1ec497cc8e7163b43a17eb5d43c784329e455ac5d0f44873d6cd9260ab0c4", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "393aa32a-a419-4bae-b130-fed76c22e93b", "node_type": "1", "metadata": {}, "hash": "05d9ba81c31cc571cddc095781768c24359b4547ab1a90e63ac426d8383af90f", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 41016, "end_char_idx": 44440, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
Ideally, you should debug/print out
intermediate outputs of both implementations of the forward pass to find the exact position in the network where the 🤗
Transformers implementation shows a different output than the original implementation. First, make sure that the
hard-coded `input_ids` in both scripts are identical. Next, verify that the outputs of the first transformation of
the `input_ids` (usually the word embeddings) are identical. And then work your way up to the very last layer of the
network. At some point, you will notice a difference between the two implementations, which should point you to the bug
in the 🤗 Transformers implementation. From our experience, a simple and efficient way is to add many print statements
in both the original implementation and 🤗 Transformers implementation, at the same positions in the network
respectively, and to successively remove print statements showing the same values for intermediate presentations.

When you're confident that both implementations yield the same output, verify the outputs with
`torch.allclose(original_output, output, atol=1e-3)`, you're done with the most difficult part! Congratulations - the
work left to be done should be a cakewalk 😊.

**8. Adding all necessary model tests**

At this point, you have successfully added a new model. However, it is very much possible that the model does not yet
fully comply with the required design. To make sure, the implementation is fully compatible with 🤗 Transformers, all
common tests should pass. The Cookiecutter should have automatically added a test file for your model, probably under
the same `tests/models/brand_new_bert/test_modeling_brand_new_bert.py`. Run this test file to verify that all common
tests pass:

```bash
pytest tests/models/brand_new_bert/test_modeling_brand_new_bert.py
```

Having fixed all common tests, it is now crucial to ensure that all the nice work you have done is well tested, so that

- a) The community can easily understand your work by looking at specific tests of *brand_new_bert*
- b) Future changes to your model will not break any important feature of the model.

At first, integration tests should be added. Those integration tests essentially do the same as the debugging scripts
you used earlier to implement the model to 🤗 Transformers. A template of those model tests has already added by the
Cookiecutter, called `BrandNewBertModelIntegrationTests` and only has to be filled out by you. To ensure that those
tests are passing, run

```bash
RUN_SLOW=1 pytest -sv tests/models/brand_new_bert/test_modeling_brand_new_bert.py::BrandNewBertModelIntegrationTests
```

<Tip>

In case you are using Windows, you should replace `RUN_SLOW=1` with `SET RUN_SLOW=1`

</Tip>

Second, all features that are special to *brand_new_bert* should be tested additionally in a separate test under
`BrandNewBertModelTester`/`BrandNewBertModelTest`. This part is often forgotten but is extremely useful in two
ways:

- It helps to transfer the knowledge you have acquired during the model addition to the community by showing how the
  special features of *brand_new_bert* should work.
- Future contributors can quickly test changes to the model by running those special tests.


**9. Implement the tokenizer**

Next, we should add the tokenizer of *brand_new_bert*. Usually, the tokenizer is equivalent to or very similar to an
already existing tokenizer of 🤗 Transformers.


key: _node_content
string_value:
{"id_": "393aa32a-a419-4bae-b130-fed76c22e93b", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "77a5c54c-d9c7-487a-b20e-227d344691f1", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "be29d9066a3bb5441b934b61b5d05206f35f293fe5db6f3425d392ae829363e0", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "fe410dab-f86b-43bf-9b42-f39c736db694", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "e92d513358e6efbbc5180907b5e5cf18520d028ad0ba9b7e938fbadfc8a47d34", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "db57fb88-ad8b-4272-a04d-b518d4797854", "node_type": "1", "metadata": {}, "hash": "b1f7182610ff5e7000eb4d67ae7bf2b76a40d9415a374d494774d07bb476ccb8", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 43147, "end_char_idx": 46452, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
At first, integration tests should be added. Those integration tests essentially do the same as the debugging scripts
you used earlier to implement the model to 🤗 Transformers. A template of those model tests has already added by the
Cookiecutter, called `BrandNewBertModelIntegrationTests` and only has to be filled out by you. To ensure that those
tests are passing, run

```bash
RUN_SLOW=1 pytest -sv tests/models/brand_new_bert/test_modeling_brand_new_bert.py::BrandNewBertModelIntegrationTests
```

<Tip>

In case you are using Windows, you should replace `RUN_SLOW=1` with `SET RUN_SLOW=1`

</Tip>

Second, all features that are special to *brand_new_bert* should be tested additionally in a separate test under
`BrandNewBertModelTester`/`BrandNewBertModelTest`. This part is often forgotten but is extremely useful in two
ways:

- It helps to transfer the knowledge you have acquired during the model addition to the community by showing how the
  special features of *brand_new_bert* should work.
- Future contributors can quickly test changes to the model by running those special tests.


**9. Implement the tokenizer**

Next, we should add the tokenizer of *brand_new_bert*. Usually, the tokenizer is equivalent to or very similar to an
already existing tokenizer of 🤗 Transformers.

It is very important to find/extract the original tokenizer file and to manage to load this file into the 🤗
Transformers' implementation of the tokenizer.

To ensure that the tokenizer works correctly, it is recommended to first create a script in the original repository
that inputs a string and returns the `input_ids`. It could look similar to this (in pseudo-code):

```python
input_str = "This is a long example input string containing special characters .$?-, numbers 2872 234 12 and words."
model = BrandNewBertModel.load_pretrained_checkpoint("/path/to/checkpoint/")
input_ids = model.tokenize(input_str)
```

You might have to take a deeper look again into the original repository to find the correct tokenizer function or you
might even have to do changes to your clone of the original repository to only output the `input_ids`. Having written
a functional tokenization script that uses the original repository, an analogous script for 🤗 Transformers should be
created. It should look similar to this:

```python
from transformers import BrandNewBertTokenizer

input_str = "This is a long example input string containing special characters .$?-, numbers 2872 234 12 and words."

tokenizer = BrandNewBertTokenizer.from_pretrained("/path/to/tokenizer/folder/")

input_ids = tokenizer(input_str).input_ids
```

When both `input_ids` yield the same values, as a final step a tokenizer test file should also be added.

Analogous to the modeling test files of *brand_new_bert*, the tokenization test files of *brand_new_bert* should
contain a couple of hard-coded integration tests.

**10. Run End-to-end integration tests**

Having added the tokenizer, you should also add a couple of end-to-end integration tests using both the model and the
tokenizer to `tests/models/brand_new_bert/test_modeling_brand_new_bert.py` in 🤗 Transformers.
Such a test should show on a meaningful
text-to-text sample that the 🤗 Transformers implementation works as expected. A meaningful text-to-text sample can
include *e.g.


key: _node_content
string_value:
{"id_": "db57fb88-ad8b-4272-a04d-b518d4797854", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "77a5c54c-d9c7-487a-b20e-227d344691f1", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "be29d9066a3bb5441b934b61b5d05206f35f293fe5db6f3425d392ae829363e0", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "393aa32a-a419-4bae-b130-fed76c22e93b", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "b12fb0b3148c4a2c25f28a40e1298198a61aceacf93aa91bf7782a39ac8c87f9", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "632fb896-94b3-4077-9f87-e6ccadeafdf4", "node_type": "1", "metadata": {}, "hash": "b578a32d139f003213b9aeadf7461667bf2e8219bd4a3dba8834d879e11cf3f9", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 44764, "end_char_idx": 48147, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
It could look similar to this (in pseudo-code):

```python
input_str = "This is a long example input string containing special characters .$?-, numbers 2872 234 12 and words."
model = BrandNewBertModel.load_pretrained_checkpoint("/path/to/checkpoint/")
input_ids = model.tokenize(input_str)
```

You might have to take a deeper look again into the original repository to find the correct tokenizer function or you
might even have to do changes to your clone of the original repository to only output the `input_ids`. Having written
a functional tokenization script that uses the original repository, an analogous script for 🤗 Transformers should be
created. It should look similar to this:

```python
from transformers import BrandNewBertTokenizer

input_str = "This is a long example input string containing special characters .$?-, numbers 2872 234 12 and words."

tokenizer = BrandNewBertTokenizer.from_pretrained("/path/to/tokenizer/folder/")

input_ids = tokenizer(input_str).input_ids
```

When both `input_ids` yield the same values, as a final step a tokenizer test file should also be added.

Analogous to the modeling test files of *brand_new_bert*, the tokenization test files of *brand_new_bert* should
contain a couple of hard-coded integration tests.

**10. Run End-to-end integration tests**

Having added the tokenizer, you should also add a couple of end-to-end integration tests using both the model and the
tokenizer to `tests/models/brand_new_bert/test_modeling_brand_new_bert.py` in 🤗 Transformers.
Such a test should show on a meaningful
text-to-text sample that the 🤗 Transformers implementation works as expected. A meaningful text-to-text sample can
include *e.g.* a source-to-target-translation pair, an article-to-summary pair, a question-to-answer pair, etc… If none
of the ported checkpoints has been fine-tuned on a downstream task it is enough to simply rely on the model tests. In a
final step to ensure that the model is fully functional, it is advised that you also run all tests on GPU. It can
happen that you forgot to add some `.to(self.device)` statements to internal tensors of the model, which in such a
test would show in an error. In case you have no access to a GPU, the Hugging Face team can take care of running those
tests for you.

**11. Add Docstring**

Now, all the necessary functionality for *brand_new_bert* is added - you're almost done! The only thing left to add is
a nice docstring and a doc page. The Cookiecutter should have added a template file called
`docs/source/model_doc/brand_new_bert.md` that you should fill out. Users of your model will usually first look at
this page before using your model. Hence, the documentation must be understandable and concise. It is very useful for
the community to add some *Tips* to show how the model should be used. Don't hesitate to ping the Hugging Face team
regarding the docstrings.

Next, make sure that the docstring added to `src/transformers/models/brand_new_bert/modeling_brand_new_bert.py` is
correct and included all necessary inputs and outputs. We have a detailed guide about writing documentation and our docstring format [here](writing-documentation). It is always good to remind oneself that documentation should
be treated at least as carefully as the code in 🤗 Transformers since the documentation is usually the first contact
point of the community with the model.


key: _node_content
string_value:
{"id_": "632fb896-94b3-4077-9f87-e6ccadeafdf4", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "77a5c54c-d9c7-487a-b20e-227d344691f1", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "be29d9066a3bb5441b934b61b5d05206f35f293fe5db6f3425d392ae829363e0", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "db57fb88-ad8b-4272-a04d-b518d4797854", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "3c9b406e43909e2261859af82b58dd0233be50ad28dd82b9bc3f296d84314631", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "48c48b75-a1e5-436b-a896-c7465f14861a", "node_type": "1", "metadata": {}, "hash": "9f82f4b7d877fc9637c4cfef639a74321f1dffdea649a7151c866df39e43e489", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 46452, "end_char_idx": 49833, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
* a source-to-target-translation pair, an article-to-summary pair, a question-to-answer pair, etc… If none
of the ported checkpoints has been fine-tuned on a downstream task it is enough to simply rely on the model tests. In a
final step to ensure that the model is fully functional, it is advised that you also run all tests on GPU. It can
happen that you forgot to add some `.to(self.device)` statements to internal tensors of the model, which in such a
test would show in an error. In case you have no access to a GPU, the Hugging Face team can take care of running those
tests for you.

**11. Add Docstring**

Now, all the necessary functionality for *brand_new_bert* is added - you're almost done! The only thing left to add is
a nice docstring and a doc page. The Cookiecutter should have added a template file called
`docs/source/model_doc/brand_new_bert.md` that you should fill out. Users of your model will usually first look at
this page before using your model. Hence, the documentation must be understandable and concise. It is very useful for
the community to add some *Tips* to show how the model should be used. Don't hesitate to ping the Hugging Face team
regarding the docstrings.

Next, make sure that the docstring added to `src/transformers/models/brand_new_bert/modeling_brand_new_bert.py` is
correct and included all necessary inputs and outputs. We have a detailed guide about writing documentation and our docstring format [here](writing-documentation). It is always good to remind oneself that documentation should
be treated at least as carefully as the code in 🤗 Transformers since the documentation is usually the first contact
point of the community with the model.

**Code refactor**

Great, now you have added all the necessary code for *brand_new_bert*. At this point, you should correct some potential
incorrect code style by running:

```bash
make style
```

and verify that your coding style passes the quality check:

```bash
make quality
```

There are a couple of other very strict design tests in 🤗 Transformers that might still be failing, which shows up in
the tests of your pull request. This is often because of some missing information in the docstring or some incorrect
naming. The Hugging Face team will surely help you if you're stuck here.

Lastly, it is always a good idea to refactor one's code after having ensured that the code works correctly. With all
tests passing, now it's a good time to go over the added code again and do some refactoring.

You have now finished the coding part, congratulation! 🎉 You are Awesome! 😎

**12. Upload the models to the model hub**

In this final part, you should convert and upload all checkpoints to the model hub and add a model card for each
uploaded model checkpoint. You can get familiar with the hub functionalities by reading our [Model sharing and uploading Page](model_sharing). You should work alongside the Hugging Face team here to decide on a fitting name for each
checkpoint and to get the required access rights to be able to upload the model under the author's organization of
*brand_new_bert*. The `push_to_hub` method, present in all models in `transformers`, is a quick and efficient way to push your checkpoint to the hub. A little snippet is pasted below:

```python
brand_new_bert.push_to_hub("brand_new_bert")
# Uncomment the following line to push to an organization.


key: _node_content
string_value:
{"id_": "48c48b75-a1e5-436b-a896-c7465f14861a", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "77a5c54c-d9c7-487a-b20e-227d344691f1", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "be29d9066a3bb5441b934b61b5d05206f35f293fe5db6f3425d392ae829363e0", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "632fb896-94b3-4077-9f87-e6ccadeafdf4", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/add_new_model/", "title": "How to add a model to \ud83e\udd17 Transformers?", "tokens": 12286, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "ba4b7046a166071ca0fcf2e2c01fb031b2d88d5ae52e77d9a17b25ebc18385d5", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 48149, "end_char_idx": 51422, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
**Code refactor**

Great, now you have added all the necessary code for *brand_new_bert*. At this point, you should correct some potential
incorrect code style by running:

```bash
make style
```

and verify that your coding style passes the quality check:

```bash
make quality
```

There are a couple of other very strict design tests in 🤗 Transformers that might still be failing, which shows up in
the tests of your pull request. This is often because of some missing information in the docstring or some incorrect
naming. The Hugging Face team will surely help you if you're stuck here.

Lastly, it is always a good idea to refactor one's code after having ensured that the code works correctly. With all
tests passing, now it's a good time to go over the added code again and do some refactoring.

You have now finished the coding part, congratulation! 🎉 You are Awesome! 😎

**12. Upload the models to the model hub**

In this final part, you should convert and upload all checkpoints to the model hub and add a model card for each
uploaded model checkpoint. You can get familiar with the hub functionalities by reading our [Model sharing and uploading Page](model_sharing). You should work alongside the Hugging Face team here to decide on a fitting name for each
checkpoint and to get the required access rights to be able to upload the model under the author's organization of
*brand_new_bert*. The `push_to_hub` method, present in all models in `transformers`, is a quick and efficient way to push your checkpoint to the hub. A little snippet is pasted below:

```python
brand_new_bert.push_to_hub("brand_new_bert")
# Uncomment the following line to push to an organization.
# brand_new_bert.push_to_hub("<organization>/brand_new_bert")
```

It is worth spending some time to create fitting model cards for each checkpoint. The model cards should highlight the
specific characteristics of this particular checkpoint, *e.g.* On which dataset was the checkpoint
pretrained/fine-tuned on? On what down-stream task should the model be used? And also include some code on how to
correctly use the model.

**13. (Optional) Add notebook**

It is very helpful to add a notebook that showcases in-detail how *brand_new_bert* can be used for inference and/or
fine-tuned on a downstream task. This is not mandatory to merge your PR, but very useful for the community.

**14. Submit your finished PR**

You're done programming now and can move to the last step, which is getting your PR merged into main. Usually, the
Hugging Face team should have helped you already at this point, but it is worth taking some time to give your finished
PR a nice description and eventually add comments to your code, if you want to point out certain design choices to your
reviewer.

### Share your work!!

Now, it's time to get some credit from the community for your work! Having completed a model addition is a major
contribution to Transformers and the whole NLP community. Your code and the ported pre-trained models will certainly be
used by hundreds and possibly even thousands of developers and researchers. You should be proud of your work and share
your achievements with the community.

**You have made another model that is super easy to access for everyone in the community! 🤯**


key: _node_content
string_value:
{"id_": "462ae60f-6b8e-41ee-ac01-a64fc88a6959", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/pipeline_webserver/", "title": "Using pipelines for a webserver", "tokens": 1467, "retrieve_doc": true, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6abd33ff-b43b-4fcb-befa-c3fe7b1a7d8c", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/pipeline_webserver/", "title": "Using pipelines for a webserver", "tokens": 1467, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "b5e282754550ddafe2ff0234e46d93644c664e8ca0b724a779084ae07a5717c0", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "615a5f07-dd8b-49e5-bd8e-8a67f98ee5f4", "node_type": "1", "metadata": {}, "hash": "31874c9931bb2a115e2638d7c5b9a26e10bc5f1f8f2cd2db3824b9ae774bdac2", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 0, "end_char_idx": 2361, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
<!--⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.
-->

# Using pipelines for a webserver

<Tip>
Creating an inference engine is a complex topic, and the "best" solution 
will most likely depend on your problem space. Are you on CPU or GPU? Do
you want the lowest latency, the highest throughput, support for
many models, or just highly optimize 1 specific model?
There are many ways to tackle this topic, so what we are going to present is a good default
to get started which may not necessarily be the most optimal solution for you.
</Tip>


The key thing to understand is that we can use an iterator, just like you would [on a
dataset](pipeline_tutorial#using-pipelines-on-a-dataset), since a webserver is basically a system that waits for requests and
treats them as they come in.

Usually webservers are multiplexed (multithreaded, async, etc..) to handle various
requests concurrently. Pipelines on the other hand (and mostly the underlying models)
are not really great for parallelism; they take up a lot of RAM, so it's best to give them all the available resources when they are running or it's a compute-intensive job.

We are going to solve that by having the webserver handle the light load of receiving
and sending requests, and having a single thread handling the actual work.
This example is going to use `starlette`. The actual framework is not really
important, but you might have to tune or change the code if you are using another
one to achieve the same effect.

Create `server.py`:

```py
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
from transformers import pipeline
import asyncio


async def homepage(request):
    payload = await request.body()
    string = payload.decode("utf-8")
    response_q = asyncio.Queue()
    await request.app.model_queue.put((string, response_q))
    output = await response_q.get()
    return JSONResponse(output)


async def server_loop(q):
    pipe = pipeline(model="google-bert/bert-base-uncased")
    while True:
        (string, response_q) = await q.get()
        out = pipe(string)
        await response_q.put(out)


app = Starlette(
    routes=[
        Route("/", homepage, methods=["POST"]),
    ],
)


key: _node_content
string_value:
{"id_": "615a5f07-dd8b-49e5-bd8e-8a67f98ee5f4", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/pipeline_webserver/", "title": "Using pipelines for a webserver", "tokens": 1467, "retrieve_doc": true, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6abd33ff-b43b-4fcb-befa-c3fe7b1a7d8c", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/pipeline_webserver/", "title": "Using pipelines for a webserver", "tokens": 1467, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "b5e282754550ddafe2ff0234e46d93644c664e8ca0b724a779084ae07a5717c0", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "462ae60f-6b8e-41ee-ac01-a64fc88a6959", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/pipeline_webserver/", "title": "Using pipelines for a webserver", "tokens": 1467, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "f5ecd0ecbf252bbc36599763597db83157ff2e5e54d4c37fc3403e6c9a50cf26", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "c1f1fc74-8ea7-4d3e-a8d1-157a6948d4e7", "node_type": "1", "metadata": {}, "hash": "86fe1179852aefe265940043d5a2d81a7ff6bf32971e1850fd31cc2fdaea0569", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 659, "end_char_idx": 4351, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
The key thing to understand is that we can use an iterator, just like you would [on a
dataset](pipeline_tutorial#using-pipelines-on-a-dataset), since a webserver is basically a system that waits for requests and
treats them as they come in.

Usually webservers are multiplexed (multithreaded, async, etc..) to handle various
requests concurrently. Pipelines on the other hand (and mostly the underlying models)
are not really great for parallelism; they take up a lot of RAM, so it's best to give them all the available resources when they are running or it's a compute-intensive job.

We are going to solve that by having the webserver handle the light load of receiving
and sending requests, and having a single thread handling the actual work.
This example is going to use `starlette`. The actual framework is not really
important, but you might have to tune or change the code if you are using another
one to achieve the same effect.

Create `server.py`:

```py
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
from transformers import pipeline
import asyncio


async def homepage(request):
    payload = await request.body()
    string = payload.decode("utf-8")
    response_q = asyncio.Queue()
    await request.app.model_queue.put((string, response_q))
    output = await response_q.get()
    return JSONResponse(output)


async def server_loop(q):
    pipe = pipeline(model="google-bert/bert-base-uncased")
    while True:
        (string, response_q) = await q.get()
        out = pipe(string)
        await response_q.put(out)


app = Starlette(
    routes=[
        Route("/", homepage, methods=["POST"]),
    ],
)


@app.on_event("startup")
async def startup_event():
    q = asyncio.Queue()
    app.model_queue = q
    asyncio.create_task(server_loop(q))
```

Now you can start it with:
```bash
uvicorn server:app
```

And you can query it:
```bash
curl -X POST -d "test [MASK]" http://localhost:8000/
#[{"score":0.7742936015129089,"token":1012,"token_str":".","sequence":"test."},...]
```

And there you go, now you have a good idea of how to create a webserver!

What is really important is that we load the model only **once**, so there are no copies
of the model on the webserver. This way, no unnecessary RAM is being used.
Then the queuing mechanism allows you to do fancy stuff like maybe accumulating a few
items before inferring to use dynamic batching:

<Tip warning={true}>

The code sample below is intentionally written like pseudo-code for readability.
Do not run this without checking if it makes sense for your system resources!

</Tip>

```py
(string, rq) = await q.get()
strings = []
queues = []
while True:
    try:
        (string, rq) = await asyncio.wait_for(q.get(), timeout=0.001)  # 1ms
    except asyncio.exceptions.TimeoutError:
        break
    strings.append(string)
    queues.append(rq)
strings
outs = pipe(strings, batch_size=len(strings))
for rq, out in zip(queues, outs):
    await rq.put(out)
```

Again, the proposed code is optimized for readability, not for being the best code.
First of all, there's no batch size limit which is usually not a 
great idea. Next, the timeout is reset on every queue fetch, meaning you could
wait much more than 1ms before running the inference (delaying the first request 
by that much). 

It would be better to have a single 1ms deadline.

This will always wait for 1ms even if the queue is empty, which might not be the
best since you probably want to start doing inference if there's nothing in the queue.
But maybe it does make sense if batching is really crucial for your use case.
Again, there's really no one best solution.


key: _node_content
string_value:
{"id_": "c1f1fc74-8ea7-4d3e-a8d1-157a6948d4e7", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/pipeline_webserver/", "title": "Using pipelines for a webserver", "tokens": 1467, "retrieve_doc": true, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6abd33ff-b43b-4fcb-befa-c3fe7b1a7d8c", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/pipeline_webserver/", "title": "Using pipelines for a webserver", "tokens": 1467, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "b5e282754550ddafe2ff0234e46d93644c664e8ca0b724a779084ae07a5717c0", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "615a5f07-dd8b-49e5-bd8e-8a67f98ee5f4", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/pipeline_webserver/", "title": "Using pipelines for a webserver", "tokens": 1467, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "8fcae6c1ace358474b74cd030b580293c330b3107dda3537efb144afc02d7a66", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 4354, "end_char_idx": 6456, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
## Few things you might want to consider

### Error checking

There's a lot that can go wrong in production: out of memory, out of space,
loading the model might fail, the query might be wrong, the query might be
correct but still fail to run because of a model misconfiguration, and so on.

Generally, it's good if the server outputs the errors to the user, so
adding a lot of `try..except` statements to show those errors is a good
idea. But keep in mind it may also be a security risk to reveal all those errors depending 
on your security context.

### Circuit breaking

Webservers usually look better when they do circuit breaking. It means they 
return proper errors when they're overloaded instead of just waiting for the query indefinitely. Return a 503 error instead of waiting for a super long time or a 504 after a long time.

This is relatively easy to implement in the proposed code since there is a single queue.
Looking at the queue size is a basic way to start returning errors before your 
webserver fails under load.

### Blocking the main thread

Currently PyTorch is not async aware, and computation will block the main
thread while running. That means it would be better if PyTorch was forced to run
on its own thread/process. This wasn't done here because the code is a lot more
complex (mostly because threads and async and queues don't play nice together).
But ultimately it does the same thing.

This would be important if the inference of single items were long (> 1s) because 
in this case, it means every query during inference would have to wait for 1s before
even receiving an error.

### Dynamic batching

In general, batching is not necessarily an improvement over passing 1 item at 
a time (see [batching details](./main_classes/pipelines#pipeline-batching) for more information). But it can be very effective
when used in the correct setting. In the API, there is no dynamic
batching by default (too much opportunity for a slowdown). But for BLOOM inference -
which is a very large model - dynamic batching is **essential** to provide a decent experience for everyone.


key: _node_content
string_value:
{"id_": "12df90f1-2826-4cac-aab9-b83e2ac2fffe", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "1eada467-4eea-4941-a140-054be28ff7c7", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "410ebbb958a020a6aed2a6e636db514e6d6968a5bd384abdcf41c29f8b010ee6", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "0c8cd816-ff4e-4768-98b1-4cb3c67d1dac", "node_type": "1", "metadata": {}, "hash": "db3529fe6abeda9c5d241bad9e2a829cc3ea91c3fdedb579edc6c756ecd10fb9", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 0, "end_char_idx": 2987, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
# Summary of the tokenizers

[[open-in-colab]]

On this page, we will have a closer look at tokenization.

<Youtube id="VFp38yj8h3A"/>

As we saw in [the preprocessing tutorial](preprocessing), tokenizing a text is splitting it into words or
subwords, which then are converted to ids through a look-up table. Converting words or subwords to ids is
straightforward, so in this summary, we will focus on splitting a text into words or subwords (i.e. tokenizing a text).
More specifically, we will look at the three main types of tokenizers used in 🤗 Transformers: [Byte-Pair Encoding
(BPE)](#byte-pair-encoding), [WordPiece](#wordpiece), and [SentencePiece](#sentencepiece), and show examples
of which tokenizer type is used by which model.

Note that on each model page, you can look at the documentation of the associated tokenizer to know which tokenizer
type was used by the pretrained model. For instance, if we look at [`BertTokenizer`], we can see
that the model uses [WordPiece](#wordpiece).

## Introduction

Splitting a text into smaller chunks is a task that is harder than it looks, and there are multiple ways of doing so.
For instance, let's look at the sentence `"Don't you love 🤗 Transformers? We sure do."`

<Youtube id="nhJxYji1aho"/>

A simple way of tokenizing this text is to split it by spaces, which would give:

```
["Don't", "you", "love", "🤗", "Transformers?", "We", "sure", "do."]
```

This is a sensible first step, but if we look at the tokens `"Transformers?"` and `"do."`, we notice that the
punctuation is attached to the words `"Transformer"` and `"do"`, which is suboptimal. We should take the
punctuation into account so that a model does not have to learn a different representation of a word and every possible
punctuation symbol that could follow it, which would explode the number of representations the model has to learn.
Taking punctuation into account, tokenizing our exemplary text would give:

```
["Don", "'", "t", "you", "love", "🤗", "Transformers", "?", "We", "sure", "do", "."]
```

Better. However, it is disadvantageous, how the tokenization dealt with the word `"Don't"`. `"Don't"` stands for
`"do not"`, so it would be better tokenized as `["Do", "n't"]`. This is where things start getting complicated, and
part of the reason each model has its own tokenizer type. Depending on the rules we apply for tokenizing a text, a
different tokenized output is generated for the same text. A pretrained model only performs properly if you feed it an
input that was tokenized with the same rules that were used to tokenize its training data.

[spaCy](https://spacy.io/) and [Moses](http://www.statmt.org/moses/?n=Development.GetStarted) are two popular
rule-based tokenizers. Applying them on our example, *spaCy* and *Moses* would output something like:

```
["Do", "n't", "you", "love", "🤗", "Transformers", "?", "We", "sure", "do", "."]
```

As can be seen space and punctuation tokenization, as well as rule-based tokenization, is used here.


key: _node_content
string_value:
{"id_": "0c8cd816-ff4e-4768-98b1-4cb3c67d1dac", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "1eada467-4eea-4941-a140-054be28ff7c7", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "410ebbb958a020a6aed2a6e636db514e6d6968a5bd384abdcf41c29f8b010ee6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "12df90f1-2826-4cac-aab9-b83e2ac2fffe", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "8cd89f0d0ee3a79317622ba12dfc7cd7f2a126db757b547ed913e2d948ef0991", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "d4c4ed39-b89f-4bb5-8a17-e95db8fc3d04", "node_type": "1", "metadata": {}, "hash": "12952e2eeb2e588dcf770a55cc4742f6cb495c4da0b3005a36eed67e9427fe04", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 1486, "end_char_idx": 4839, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
"` and `"do."`, we notice that the
punctuation is attached to the words `"Transformer"` and `"do"`, which is suboptimal. We should take the
punctuation into account so that a model does not have to learn a different representation of a word and every possible
punctuation symbol that could follow it, which would explode the number of representations the model has to learn.
Taking punctuation into account, tokenizing our exemplary text would give:

```
["Don", "'", "t", "you", "love", "🤗", "Transformers", "?", "We", "sure", "do", "."]
```

Better. However, it is disadvantageous, how the tokenization dealt with the word `"Don't"`. `"Don't"` stands for
`"do not"`, so it would be better tokenized as `["Do", "n't"]`. This is where things start getting complicated, and
part of the reason each model has its own tokenizer type. Depending on the rules we apply for tokenizing a text, a
different tokenized output is generated for the same text. A pretrained model only performs properly if you feed it an
input that was tokenized with the same rules that were used to tokenize its training data.

[spaCy](https://spacy.io/) and [Moses](http://www.statmt.org/moses/?n=Development.GetStarted) are two popular
rule-based tokenizers. Applying them on our example, *spaCy* and *Moses* would output something like:

```
["Do", "n't", "you", "love", "🤗", "Transformers", "?", "We", "sure", "do", "."]
```

As can be seen space and punctuation tokenization, as well as rule-based tokenization, is used here. Space and
punctuation tokenization and rule-based tokenization are both examples of word tokenization, which is loosely defined
as splitting sentences into words. While it's the most intuitive way to split texts into smaller chunks, this
tokenization method can lead to problems for massive text corpora. In this case, space and punctuation tokenization
usually generates a very big vocabulary (the set of all unique words and tokens used). *E.g.*, [Transformer XL](model_doc/transfo-xl) uses space and punctuation tokenization, resulting in a vocabulary size of 267,735!

Such a big vocabulary size forces the model to have an enormous embedding matrix as the input and output layer, which
causes both an increased memory and time complexity. In general, transformers models rarely have a vocabulary size
greater than 50,000, especially if they are pretrained only on a single language.

So if simple space and punctuation tokenization is unsatisfactory, why not simply tokenize on characters?

<Youtube id="ssLq_EK2jLE"/>

While character tokenization is very simple and would greatly reduce memory and time complexity it makes it much harder
for the model to learn meaningful input representations. *E.g.* learning a meaningful context-independent
representation for the letter `"t"` is much harder than learning a context-independent representation for the word
`"today"`. Therefore, character tokenization is often accompanied by a loss of performance. So to get the best of
both worlds, transformers models use a hybrid between word-level and character-level tokenization called **subword**
tokenization.

## Subword tokenization

<Youtube id="zHvTiHr506c"/>

Subword tokenization algorithms rely on the principle that frequently used words should not be split into smaller
subwords, but rare words should be decomposed into meaningful subwords.


key: _node_content
string_value:
{"id_": "d4c4ed39-b89f-4bb5-8a17-e95db8fc3d04", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "1eada467-4eea-4941-a140-054be28ff7c7", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "410ebbb958a020a6aed2a6e636db514e6d6968a5bd384abdcf41c29f8b010ee6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "0c8cd816-ff4e-4768-98b1-4cb3c67d1dac", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "cec725f9d29c314bf754f24aea3b32d1dc928e859242c1e03b95c7c8291ebecd", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "24d675c6-c6ea-4781-8b8f-0c342a61a00f", "node_type": "1", "metadata": {}, "hash": "6cd62ebc4905a3ea204968a163181fe8fd52ef3f38fb71d2404c14e9a275a605", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 2988, "end_char_idx": 6346, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
Space and
punctuation tokenization and rule-based tokenization are both examples of word tokenization, which is loosely defined
as splitting sentences into words. While it's the most intuitive way to split texts into smaller chunks, this
tokenization method can lead to problems for massive text corpora. In this case, space and punctuation tokenization
usually generates a very big vocabulary (the set of all unique words and tokens used). *E.g.*, [Transformer XL](model_doc/transfo-xl) uses space and punctuation tokenization, resulting in a vocabulary size of 267,735!

Such a big vocabulary size forces the model to have an enormous embedding matrix as the input and output layer, which
causes both an increased memory and time complexity. In general, transformers models rarely have a vocabulary size
greater than 50,000, especially if they are pretrained only on a single language.

So if simple space and punctuation tokenization is unsatisfactory, why not simply tokenize on characters?

<Youtube id="ssLq_EK2jLE"/>

While character tokenization is very simple and would greatly reduce memory and time complexity it makes it much harder
for the model to learn meaningful input representations. *E.g.* learning a meaningful context-independent
representation for the letter `"t"` is much harder than learning a context-independent representation for the word
`"today"`. Therefore, character tokenization is often accompanied by a loss of performance. So to get the best of
both worlds, transformers models use a hybrid between word-level and character-level tokenization called **subword**
tokenization.

## Subword tokenization

<Youtube id="zHvTiHr506c"/>

Subword tokenization algorithms rely on the principle that frequently used words should not be split into smaller
subwords, but rare words should be decomposed into meaningful subwords. For instance `"annoyingly"` might be
considered a rare word and could be decomposed into `"annoying"` and `"ly"`. Both `"annoying"` and `"ly"` as
stand-alone subwords would appear more frequently while at the same time the meaning of `"annoyingly"` is kept by the
composite meaning of `"annoying"` and `"ly"`. This is especially useful in agglutinative languages such as Turkish,
where you can form (almost) arbitrarily long complex words by stringing together subwords.

Subword tokenization allows the model to have a reasonable vocabulary size while being able to learn meaningful
context-independent representations. In addition, subword tokenization enables the model to process words it has never
seen before, by decomposing them into known subwords. For instance, the [`~transformers.BertTokenizer`] tokenizes
`"I have a new GPU!"` as follows:

```py
>>> from transformers import BertTokenizer

>>> tokenizer = BertTokenizer.from_pretrained("google-bert/bert-base-uncased")
>>> tokenizer.tokenize("I have a new GPU!")
["i", "have", "a", "new", "gp", "##u", "!"]
```

Because we are considering the uncased model, the sentence was lowercased first. We can see that the words `["i", "have", "a", "new"]` are present in the tokenizer's vocabulary, but the word `"gpu"` is not. Consequently, the
tokenizer splits `"gpu"` into known subwords: `["gp" and "##u"]`. `"##"` means that the rest of the token should
be attached to the previous one, without space (for decoding or reversal of the tokenization).


key: _node_content
string_value:
{"id_": "24d675c6-c6ea-4781-8b8f-0c342a61a00f", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "1eada467-4eea-4941-a140-054be28ff7c7", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "410ebbb958a020a6aed2a6e636db514e6d6968a5bd384abdcf41c29f8b010ee6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "d4c4ed39-b89f-4bb5-8a17-e95db8fc3d04", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "f8b11b545949134c12b7981bdec6e0c98c0addbbb1519afb423a3e7d08f4654e", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "36696fe0-bef7-4889-9aec-a2747ce22d2e", "node_type": "1", "metadata": {}, "hash": "c6c5e8c3eea22dd0b14b73f8fa92e985fd47836293203981f8d77ceb9d6a0938", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 4840, "end_char_idx": 7687, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
For instance `"annoyingly"` might be
considered a rare word and could be decomposed into `"annoying"` and `"ly"`. Both `"annoying"` and `"ly"` as
stand-alone subwords would appear more frequently while at the same time the meaning of `"annoyingly"` is kept by the
composite meaning of `"annoying"` and `"ly"`. This is especially useful in agglutinative languages such as Turkish,
where you can form (almost) arbitrarily long complex words by stringing together subwords.

Subword tokenization allows the model to have a reasonable vocabulary size while being able to learn meaningful
context-independent representations. In addition, subword tokenization enables the model to process words it has never
seen before, by decomposing them into known subwords. For instance, the [`~transformers.BertTokenizer`] tokenizes
`"I have a new GPU!"` as follows:

```py
>>> from transformers import BertTokenizer

>>> tokenizer = BertTokenizer.from_pretrained("google-bert/bert-base-uncased")
>>> tokenizer.tokenize("I have a new GPU!")
["i", "have", "a", "new", "gp", "##u", "!"]
```

Because we are considering the uncased model, the sentence was lowercased first. We can see that the words `["i", "have", "a", "new"]` are present in the tokenizer's vocabulary, but the word `"gpu"` is not. Consequently, the
tokenizer splits `"gpu"` into known subwords: `["gp" and "##u"]`. `"##"` means that the rest of the token should
be attached to the previous one, without space (for decoding or reversal of the tokenization).

As another example, [`~transformers.XLNetTokenizer`] tokenizes our previously exemplary text as follows:

```py
>>> from transformers import XLNetTokenizer

>>> tokenizer = XLNetTokenizer.from_pretrained("xlnet/xlnet-base-cased")
>>> tokenizer.tokenize("Don't you love 🤗 Transformers? We sure do.")
["▁Don", "'", "t", "▁you", "▁love", "▁", "🤗", "▁", "Transform", "ers", "?", "▁We", "▁sure", "▁do", "."]
```

We'll get back to the meaning of those `"▁"` when we look at [SentencePiece](#sentencepiece). As one can see,
the rare word `"Transformers"` has been split into the more frequent subwords `"Transform"` and `"ers"`.

Let's now look at how the different subword tokenization algorithms work. Note that all of those tokenization
algorithms rely on some form of training which is usually done on the corpus the corresponding model will be trained
on.

<a id='byte-pair-encoding'></a>

### Byte-Pair Encoding (BPE)

Byte-Pair Encoding (BPE) was introduced in [Neural Machine Translation of Rare Words with Subword Units (Sennrich et
al., 2015)](https://arxiv.org/abs/1508.07909). BPE relies on a pre-tokenizer that splits the training data into
words. Pretokenization can be as simple as space tokenization, e.g. [GPT-2](model_doc/gpt2), [RoBERTa](model_doc/roberta). More advanced pre-tokenization include rule-based tokenization, e.g.


key: _node_content
string_value:
{"id_": "36696fe0-bef7-4889-9aec-a2747ce22d2e", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "1eada467-4eea-4941-a140-054be28ff7c7", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "410ebbb958a020a6aed2a6e636db514e6d6968a5bd384abdcf41c29f8b010ee6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "24d675c6-c6ea-4781-8b8f-0c342a61a00f", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "68cd528c899fccd2e7244f187ed0b1a80ee2b23fcad3cfd8962ba05ae34e4c31", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "0cc3e0a3-6dd0-4039-a2ed-c620f40b4115", "node_type": "1", "metadata": {}, "hash": "b463e05c505295089811a339bbdd796d62a84bc1986c11f4ea6b017a8e413dde", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 6348, "end_char_idx": 8974, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
As another example, [`~transformers.XLNetTokenizer`] tokenizes our previously exemplary text as follows:

```py
>>> from transformers import XLNetTokenizer

>>> tokenizer = XLNetTokenizer.from_pretrained("xlnet/xlnet-base-cased")
>>> tokenizer.tokenize("Don't you love 🤗 Transformers? We sure do.")
["▁Don", "'", "t", "▁you", "▁love", "▁", "🤗", "▁", "Transform", "ers", "?", "▁We", "▁sure", "▁do", "."]
```

We'll get back to the meaning of those `"▁"` when we look at [SentencePiece](#sentencepiece). As one can see,
the rare word `"Transformers"` has been split into the more frequent subwords `"Transform"` and `"ers"`.

Let's now look at how the different subword tokenization algorithms work. Note that all of those tokenization
algorithms rely on some form of training which is usually done on the corpus the corresponding model will be trained
on.

<a id='byte-pair-encoding'></a>

### Byte-Pair Encoding (BPE)

Byte-Pair Encoding (BPE) was introduced in [Neural Machine Translation of Rare Words with Subword Units (Sennrich et
al., 2015)](https://arxiv.org/abs/1508.07909). BPE relies on a pre-tokenizer that splits the training data into
words. Pretokenization can be as simple as space tokenization, e.g. [GPT-2](model_doc/gpt2), [RoBERTa](model_doc/roberta). More advanced pre-tokenization include rule-based tokenization, e.g. [XLM](model_doc/xlm),
[FlauBERT](model_doc/flaubert) which uses Moses for most languages, or [GPT](model_doc/openai-gpt) which uses
spaCy and ftfy, to count the frequency of each word in the training corpus.

After pre-tokenization, a set of unique words has been created and the frequency with which each word occurred in the
training data has been determined. Next, BPE creates a base vocabulary consisting of all symbols that occur in the set
of unique words and learns merge rules to form a new symbol from two symbols of the base vocabulary. It does so until
the vocabulary has attained the desired vocabulary size. Note that the desired vocabulary size is a hyperparameter to
define before training the tokenizer.

As an example, let's assume that after pre-tokenization, the following set of words including their frequency has been
determined:

```
("hug", 10), ("pug", 5), ("pun", 12), ("bun", 4), ("hugs", 5)
```

Consequently, the base vocabulary is `["b", "g", "h", "n", "p", "s", "u"]`. Splitting all words into symbols of the
base vocabulary, we obtain:

```
("h" "u" "g", 10), ("p" "u" "g", 5), ("p" "u" "n", 12), ("b" "u" "n", 4), ("h" "u" "g" "s", 5)
```

BPE then counts the frequency of each possible symbol pair and picks the symbol pair that occurs most frequently.


key: _node_content
string_value:
{"id_": "0cc3e0a3-6dd0-4039-a2ed-c620f40b4115", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "1eada467-4eea-4941-a140-054be28ff7c7", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "410ebbb958a020a6aed2a6e636db514e6d6968a5bd384abdcf41c29f8b010ee6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "36696fe0-bef7-4889-9aec-a2747ce22d2e", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "b05969b914c177c01c0825a282da9858a48f2cd5a64fef7eace8e3fbd763e743", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "3dcb396a-9070-4373-bc7a-9253723f98db", "node_type": "1", "metadata": {}, "hash": "a14ad6ae7ead94441aaf990b0210e8524805459183184d162385a0094aa1ff39", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 7619, "end_char_idx": 9852, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
More advanced pre-tokenization include rule-based tokenization, e.g. [XLM](model_doc/xlm),
[FlauBERT](model_doc/flaubert) which uses Moses for most languages, or [GPT](model_doc/openai-gpt) which uses
spaCy and ftfy, to count the frequency of each word in the training corpus.

After pre-tokenization, a set of unique words has been created and the frequency with which each word occurred in the
training data has been determined. Next, BPE creates a base vocabulary consisting of all symbols that occur in the set
of unique words and learns merge rules to form a new symbol from two symbols of the base vocabulary. It does so until
the vocabulary has attained the desired vocabulary size. Note that the desired vocabulary size is a hyperparameter to
define before training the tokenizer.

As an example, let's assume that after pre-tokenization, the following set of words including their frequency has been
determined:

```
("hug", 10), ("pug", 5), ("pun", 12), ("bun", 4), ("hugs", 5)
```

Consequently, the base vocabulary is `["b", "g", "h", "n", "p", "s", "u"]`. Splitting all words into symbols of the
base vocabulary, we obtain:

```
("h" "u" "g", 10), ("p" "u" "g", 5), ("p" "u" "n", 12), ("b" "u" "n", 4), ("h" "u" "g" "s", 5)
```

BPE then counts the frequency of each possible symbol pair and picks the symbol pair that occurs most frequently. In
the example above `"h"` followed by `"u"` is present _10 + 5 = 15_ times (10 times in the 10 occurrences of
`"hug"`, 5 times in the 5 occurrences of `"hugs"`). However, the most frequent symbol pair is `"u"` followed by
`"g"`, occurring _10 + 5 + 5 = 20_ times in total. Thus, the first merge rule the tokenizer learns is to group all
`"u"` symbols followed by a `"g"` symbol together. Next, `"ug"` is added to the vocabulary. The set of words then
becomes

```
("h" "ug", 10), ("p" "ug", 5), ("p" "u" "n", 12), ("b" "u" "n", 4), ("h" "ug" "s", 5)
```

BPE then identifies the next most common symbol pair. It's `"u"` followed by `"n"`, which occurs 16 times. `"u"`,
`"n"` is merged to `"un"` and added to the vocabulary. The next most frequent symbol pair is `"h"` followed by
`"ug"`, occurring 15 times. Again the pair is merged and `"hug"` can be added to the vocabulary.


key: _node_content
string_value:
{"id_": "3dcb396a-9070-4373-bc7a-9253723f98db", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "1eada467-4eea-4941-a140-054be28ff7c7", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "410ebbb958a020a6aed2a6e636db514e6d6968a5bd384abdcf41c29f8b010ee6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "0cc3e0a3-6dd0-4039-a2ed-c620f40b4115", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "ffa4549194dc1a6f78f2d0d4cb0a8b13b4a5415237df6fc02792f8343b72592c", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "d9a4b540-d08e-486b-99c5-49e02bf50b71", "node_type": "1", "metadata": {}, "hash": "f03416eb1ee2ab84639acbb41e711ba0a065200d3dcd0f889f0354857f0fec62", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 8688, "end_char_idx": 11159, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
Splitting all words into symbols of the
base vocabulary, we obtain:

```
("h" "u" "g", 10), ("p" "u" "g", 5), ("p" "u" "n", 12), ("b" "u" "n", 4), ("h" "u" "g" "s", 5)
```

BPE then counts the frequency of each possible symbol pair and picks the symbol pair that occurs most frequently. In
the example above `"h"` followed by `"u"` is present _10 + 5 = 15_ times (10 times in the 10 occurrences of
`"hug"`, 5 times in the 5 occurrences of `"hugs"`). However, the most frequent symbol pair is `"u"` followed by
`"g"`, occurring _10 + 5 + 5 = 20_ times in total. Thus, the first merge rule the tokenizer learns is to group all
`"u"` symbols followed by a `"g"` symbol together. Next, `"ug"` is added to the vocabulary. The set of words then
becomes

```
("h" "ug", 10), ("p" "ug", 5), ("p" "u" "n", 12), ("b" "u" "n", 4), ("h" "ug" "s", 5)
```

BPE then identifies the next most common symbol pair. It's `"u"` followed by `"n"`, which occurs 16 times. `"u"`,
`"n"` is merged to `"un"` and added to the vocabulary. The next most frequent symbol pair is `"h"` followed by
`"ug"`, occurring 15 times. Again the pair is merged and `"hug"` can be added to the vocabulary.

At this stage, the vocabulary is `["b", "g", "h", "n", "p", "s", "u", "ug", "un", "hug"]` and our set of unique words
is represented as

```
("hug", 10), ("p" "ug", 5), ("p" "un", 12), ("b" "un", 4), ("hug" "s", 5)
```

Assuming, that the Byte-Pair Encoding training would stop at this point, the learned merge rules would then be applied
to new words (as long as those new words do not include symbols that were not in the base vocabulary). For instance,
the word `"bug"` would be tokenized to `["b", "ug"]` but `"mug"` would be tokenized as `["<unk>", "ug"]` since
the symbol `"m"` is not in the base vocabulary. In general, single letters such as `"m"` are not replaced by the
`"<unk>"` symbol because the training data usually includes at least one occurrence of each letter, but it is likely
to happen for very special characters like emojis.

As mentioned earlier, the vocabulary size, *i.e.* the base vocabulary size + the number of merges, is a hyperparameter
to choose. For instance [GPT](model_doc/openai-gpt) has a vocabulary size of 40,478 since they have 478 base characters
and chose to stop training after 40,000 merges.

#### Byte-level BPE

A base vocabulary that includes all possible base characters can be quite large if *e.g.* all unicode characters are
considered as base characters.


key: _node_content
string_value:
{"id_": "d9a4b540-d08e-486b-99c5-49e02bf50b71", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "1eada467-4eea-4941-a140-054be28ff7c7", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "410ebbb958a020a6aed2a6e636db514e6d6968a5bd384abdcf41c29f8b010ee6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "3dcb396a-9070-4373-bc7a-9253723f98db", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "e9ecaef5084d605a48ed6e3e72e45bb55b81d0073ef8d220c1a36c007bdf7c07", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "5cd308eb-5995-47b5-a999-3c2998419085", "node_type": "1", "metadata": {}, "hash": "096dc6670b28c3da7686e7d8d73d9c20b0fe65f87dc6a27c11a5a797cfc34441", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 9784, "end_char_idx": 12819, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
Again the pair is merged and `"hug"` can be added to the vocabulary.

At this stage, the vocabulary is `["b", "g", "h", "n", "p", "s", "u", "ug", "un", "hug"]` and our set of unique words
is represented as

```
("hug", 10), ("p" "ug", 5), ("p" "un", 12), ("b" "un", 4), ("hug" "s", 5)
```

Assuming, that the Byte-Pair Encoding training would stop at this point, the learned merge rules would then be applied
to new words (as long as those new words do not include symbols that were not in the base vocabulary). For instance,
the word `"bug"` would be tokenized to `["b", "ug"]` but `"mug"` would be tokenized as `["<unk>", "ug"]` since
the symbol `"m"` is not in the base vocabulary. In general, single letters such as `"m"` are not replaced by the
`"<unk>"` symbol because the training data usually includes at least one occurrence of each letter, but it is likely
to happen for very special characters like emojis.

As mentioned earlier, the vocabulary size, *i.e.* the base vocabulary size + the number of merges, is a hyperparameter
to choose. For instance [GPT](model_doc/openai-gpt) has a vocabulary size of 40,478 since they have 478 base characters
and chose to stop training after 40,000 merges.

#### Byte-level BPE

A base vocabulary that includes all possible base characters can be quite large if *e.g.* all unicode characters are
considered as base characters. To have a better base vocabulary, [GPT-2](https://cdn.openai.com/better-language-models/language_models_are_unsupervised_multitask_learners.pdf) uses bytes
as the base vocabulary, which is a clever trick to force the base vocabulary to be of size 256 while ensuring that
every base character is included in the vocabulary. With some additional rules to deal with punctuation, the GPT2's
tokenizer can tokenize every text without the need for the <unk> symbol. [GPT-2](model_doc/gpt) has a vocabulary
size of 50,257, which corresponds to the 256 bytes base tokens, a special end-of-text token and the symbols learned
with 50,000 merges.

<a id='wordpiece'></a>

### WordPiece

WordPiece is the subword tokenization algorithm used for [BERT](model_doc/bert), [DistilBERT](model_doc/distilbert), and [Electra](model_doc/electra). The algorithm was outlined in [Japanese and Korean
Voice Search (Schuster et al., 2012)](https://static.googleusercontent.com/media/research.google.com/ja//pubs/archive/37842.pdf) and is very similar to
BPE. WordPiece first initializes the vocabulary to include every character present in the training data and
progressively learns a given number of merge rules. In contrast to BPE, WordPiece does not choose the most frequent
symbol pair, but the one that maximizes the likelihood of the training data once added to the vocabulary.

So what does this mean exactly? Referring to the previous example, maximizing the likelihood of the training data is
equivalent to finding the symbol pair, whose probability divided by the probabilities of its first symbol followed by
its second symbol is the greatest among all symbol pairs. *E.g.


key: _node_content
string_value:
{"id_": "5cd308eb-5995-47b5-a999-3c2998419085", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "1eada467-4eea-4941-a140-054be28ff7c7", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "410ebbb958a020a6aed2a6e636db514e6d6968a5bd384abdcf41c29f8b010ee6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "d9a4b540-d08e-486b-99c5-49e02bf50b71", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "61090f077442d6b136e5b994d5bae80041f2d0b03d94c1eeea274433ee74a53a", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "c315c8e7-cda1-412c-a5b5-cb09a8997490", "node_type": "1", "metadata": {}, "hash": "a199022d28c511731e84149e966ab1cece3b7efff923c849eefe3ece8bc35744", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 11160, "end_char_idx": 14493, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
To have a better base vocabulary, [GPT-2](https://cdn.openai.com/better-language-models/language_models_are_unsupervised_multitask_learners.pdf) uses bytes
as the base vocabulary, which is a clever trick to force the base vocabulary to be of size 256 while ensuring that
every base character is included in the vocabulary. With some additional rules to deal with punctuation, the GPT2's
tokenizer can tokenize every text without the need for the <unk> symbol. [GPT-2](model_doc/gpt) has a vocabulary
size of 50,257, which corresponds to the 256 bytes base tokens, a special end-of-text token and the symbols learned
with 50,000 merges.

<a id='wordpiece'></a>

### WordPiece

WordPiece is the subword tokenization algorithm used for [BERT](model_doc/bert), [DistilBERT](model_doc/distilbert), and [Electra](model_doc/electra). The algorithm was outlined in [Japanese and Korean
Voice Search (Schuster et al., 2012)](https://static.googleusercontent.com/media/research.google.com/ja//pubs/archive/37842.pdf) and is very similar to
BPE. WordPiece first initializes the vocabulary to include every character present in the training data and
progressively learns a given number of merge rules. In contrast to BPE, WordPiece does not choose the most frequent
symbol pair, but the one that maximizes the likelihood of the training data once added to the vocabulary.

So what does this mean exactly? Referring to the previous example, maximizing the likelihood of the training data is
equivalent to finding the symbol pair, whose probability divided by the probabilities of its first symbol followed by
its second symbol is the greatest among all symbol pairs. *E.g.* `"u"`, followed by `"g"` would have only been
merged if the probability of `"ug"` divided by `"u"`, `"g"` would have been greater than for any other symbol
pair. Intuitively, WordPiece is slightly different to BPE in that it evaluates what it _loses_ by merging two symbols
to ensure it's _worth it_.

<a id='unigram'></a>

### Unigram

Unigram is a subword tokenization algorithm introduced in [Subword Regularization: Improving Neural Network Translation
Models with Multiple Subword Candidates (Kudo, 2018)](https://arxiv.org/pdf/1804.10959.pdf). In contrast to BPE or
WordPiece, Unigram initializes its base vocabulary to a large number of symbols and progressively trims down each
symbol to obtain a smaller vocabulary. The base vocabulary could for instance correspond to all pre-tokenized words and
the most common substrings. Unigram is not used directly for any of the models in the transformers, but it's used in
conjunction with [SentencePiece](#sentencepiece).

At each training step, the Unigram algorithm defines a loss (often defined as the log-likelihood) over the training
data given the current vocabulary and a unigram language model. Then, for each symbol in the vocabulary, the algorithm
computes how much the overall loss would increase if the symbol was to be removed from the vocabulary. Unigram then
removes p (with p usually being 10% or 20%) percent of the symbols whose loss increase is the lowest, *i.e.* those
symbols that least affect the overall loss over the training data. This process is repeated until the vocabulary has
reached the desired size. The Unigram algorithm always keeps the base characters so that any word can be tokenized.


key: _node_content
string_value:
{"id_": "c315c8e7-cda1-412c-a5b5-cb09a8997490", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "1eada467-4eea-4941-a140-054be28ff7c7", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "410ebbb958a020a6aed2a6e636db514e6d6968a5bd384abdcf41c29f8b010ee6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "5cd308eb-5995-47b5-a999-3c2998419085", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "9d9ea7d5e79c669bd79f72cc0ed72b6bc43f80fca58d20c97f47c66911076701", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "157ad65d-f07c-4a63-8c5f-d3059167708a", "node_type": "1", "metadata": {}, "hash": "f1e792802583c60c44ef6f9ed6afd3ea851b1f0d8c7af63f931be4901c2b39d6", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 12814, "end_char_idx": 15869, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
*E.g.* `"u"`, followed by `"g"` would have only been
merged if the probability of `"ug"` divided by `"u"`, `"g"` would have been greater than for any other symbol
pair. Intuitively, WordPiece is slightly different to BPE in that it evaluates what it _loses_ by merging two symbols
to ensure it's _worth it_.

<a id='unigram'></a>

### Unigram

Unigram is a subword tokenization algorithm introduced in [Subword Regularization: Improving Neural Network Translation
Models with Multiple Subword Candidates (Kudo, 2018)](https://arxiv.org/pdf/1804.10959.pdf). In contrast to BPE or
WordPiece, Unigram initializes its base vocabulary to a large number of symbols and progressively trims down each
symbol to obtain a smaller vocabulary. The base vocabulary could for instance correspond to all pre-tokenized words and
the most common substrings. Unigram is not used directly for any of the models in the transformers, but it's used in
conjunction with [SentencePiece](#sentencepiece).

At each training step, the Unigram algorithm defines a loss (often defined as the log-likelihood) over the training
data given the current vocabulary and a unigram language model. Then, for each symbol in the vocabulary, the algorithm
computes how much the overall loss would increase if the symbol was to be removed from the vocabulary. Unigram then
removes p (with p usually being 10% or 20%) percent of the symbols whose loss increase is the lowest, *i.e.* those
symbols that least affect the overall loss over the training data. This process is repeated until the vocabulary has
reached the desired size. The Unigram algorithm always keeps the base characters so that any word can be tokenized.

Because Unigram is not based on merge rules (in contrast to BPE and WordPiece), the algorithm has several ways of
tokenizing new text after training. As an example, if a trained Unigram tokenizer exhibits the vocabulary:

```
["b", "g", "h", "n", "p", "s", "u", "ug", "un", "hug"],
```

`"hugs"` could be tokenized both as `["hug", "s"]`, `["h", "ug", "s"]` or `["h", "u", "g", "s"]`. So which one
to choose? Unigram saves the probability of each token in the training corpus on top of saving the vocabulary so that
the probability of each possible tokenization can be computed after training. The algorithm simply picks the most
likely tokenization in practice, but also offers the possibility to sample a possible tokenization according to their
probabilities.

Those probabilities are defined by the loss the tokenizer is trained on. Assuming that the training data consists of
the words \\(x_{1}, \dots, x_{N}\\) and that the set of all possible tokenizations for a word \\(x_{i}\\) is
defined as \\(S(x_{i})\\), then the overall loss is defined as

$$\mathcal{L} = -\sum_{i=1}^{N} \log \left ( \sum_{x \in S(x_{i})} p(x) \right )$$

<a id='sentencepiece'></a>

### SentencePiece

All tokenization algorithms described so far have the same problem: It is assumed that the input text uses spaces to
separate words. However, not all languages use spaces to separate words.


key: _node_content
string_value:
{"id_": "157ad65d-f07c-4a63-8c5f-d3059167708a", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "1eada467-4eea-4941-a140-054be28ff7c7", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "410ebbb958a020a6aed2a6e636db514e6d6968a5bd384abdcf41c29f8b010ee6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "c315c8e7-cda1-412c-a5b5-cb09a8997490", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/tokenizer_summary/", "title": "Summary of the tokenizers", "tokens": 4431, "retrieve_doc": true, "source": "HF_Transformers"}, "hash": "e5168b9b94beb12a4034d97541caa2071fe00c68caa68d1a206989f2192f1eb3", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 14404, "end_char_idx": 16925, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
The Unigram algorithm always keeps the base characters so that any word can be tokenized.

Because Unigram is not based on merge rules (in contrast to BPE and WordPiece), the algorithm has several ways of
tokenizing new text after training. As an example, if a trained Unigram tokenizer exhibits the vocabulary:

```
["b", "g", "h", "n", "p", "s", "u", "ug", "un", "hug"],
```

`"hugs"` could be tokenized both as `["hug", "s"]`, `["h", "ug", "s"]` or `["h", "u", "g", "s"]`. So which one
to choose? Unigram saves the probability of each token in the training corpus on top of saving the vocabulary so that
the probability of each possible tokenization can be computed after training. The algorithm simply picks the most
likely tokenization in practice, but also offers the possibility to sample a possible tokenization according to their
probabilities.

Those probabilities are defined by the loss the tokenizer is trained on. Assuming that the training data consists of
the words \\(x_{1}, \dots, x_{N}\\) and that the set of all possible tokenizations for a word \\(x_{i}\\) is
defined as \\(S(x_{i})\\), then the overall loss is defined as

$$\mathcal{L} = -\sum_{i=1}^{N} \log \left ( \sum_{x \in S(x_{i})} p(x) \right )$$

<a id='sentencepiece'></a>

### SentencePiece

All tokenization algorithms described so far have the same problem: It is assumed that the input text uses spaces to
separate words. However, not all languages use spaces to separate words. One possible solution is to use language
specific pre-tokenizers, *e.g.* [XLM](model_doc/xlm) uses a specific Chinese, Japanese, and Thai pre-tokenizer.
To solve this problem more generally, [SentencePiece: A simple and language independent subword tokenizer and
detokenizer for Neural Text Processing (Kudo et al., 2018)](https://arxiv.org/pdf/1808.06226.pdf) treats the input
as a raw input stream, thus including the space in the set of characters to use. It then uses the BPE or unigram
algorithm to construct the appropriate vocabulary.

The [`XLNetTokenizer`] uses SentencePiece for example, which is also why in the example earlier the
`"▁"` character was included in the vocabulary. Decoding with SentencePiece is very easy since all tokens can just be
concatenated and `"▁"` is replaced by a space.

All transformers models in the library that use SentencePiece use it in combination with unigram. Examples of models
using SentencePiece are [ALBERT](model_doc/albert), [XLNet](model_doc/xlnet), [Marian](model_doc/marian), and [T5](model_doc/t5).


key: _node_content
string_value:
{"id_": "ad108758-e2a2-40b9-b153-f5a5a0697475", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "d7d00077-490b-4bf0-b199-2359a19b95af", "node_type": "1", "metadata": {}, "hash": "b259ba8d0f4db412c3051f2fe4331a9609ef34d1d9270717ff5e2bc90f5991a5", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 0, "end_char_idx": 2883, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
# DeepSpeed

[DeepSpeed](https://www.deepspeed.ai/) is a PyTorch optimization library that makes distributed training memory-efficient and fast. At its core is the [Zero Redundancy Optimizer (ZeRO)](https://hf.co/papers/1910.02054) which enables training large models at scale. ZeRO works in several stages:

* ZeRO-1, optimizer state partitioning across GPUs
* ZeRO-2, gradient partitioning across GPUs
* ZeRO-3, parameter partitioning across GPUs

In GPU-limited environments, ZeRO also enables offloading optimizer memory and computation from the GPU to the CPU to fit and train really large models on a single GPU. DeepSpeed is integrated with the Transformers [`Trainer`] class for all ZeRO stages and offloading. All you need to do is provide a config file or you can use a provided template. For inference, Transformers support ZeRO-3 and offloading since it allows loading huge models.

This guide will walk you through how to deploy DeepSpeed training, the features you can enable, how to setup the config files for different ZeRO stages, offloading, inference, and using DeepSpeed without the [`Trainer`].

## Installation

DeepSpeed is available to install from PyPI or Transformers (for more detailed installation options, take a look at the DeepSpeed [installation details](https://www.deepspeed.ai/tutorials/advanced-install/) or the GitHub [README](https://github.com/microsoft/deepspeed#installation)).

<Tip>

If you're having difficulties installing DeepSpeed, check the [DeepSpeed CUDA installation](../debugging#deepspeed-cuda-installation) guide. While DeepSpeed has a pip installable PyPI package, it is highly recommended to [install it from source](https://www.deepspeed.ai/tutorials/advanced-install/#install-deepspeed-from-source) to best match your hardware and to support certain features, like 1-bit Adam, which aren’t available in the PyPI distribution.

</Tip>

<hfoptions id="install">
<hfoption id="PyPI">

```bash
pip install deepspeed
```

</hfoption>
<hfoption id="Transformers">

```bash
pip install transformers[deepspeed]
```

</hfoption>
</hfoptions>

## Memory requirements

Before you begin, it is a good idea to check whether you have enough GPU and CPU memory to fit your model. DeepSpeed provides a tool for estimating the required CPU/GPU memory. For example, to estimate the memory requirements for the [bigscience/T0_3B](bigscience/T0_3B) model on a single GPU:

```bash
$ python -c 'from transformers import AutoModel; \
from deepspeed.runtime.zero.stage3 import estimate_zero3_model_states_mem_needs_all_live; \
model = AutoModel.from_pretrained("bigscience/T0_3B"); \
estimate_zero3_model_states_mem_needs_all_live(model, num_gpus_per_node=1, num_nodes=1)'
[...]
Estimated memory needed for params, optim states and gradients for a:
HW: Setup with 1 node, 1 GPU per node.
SW: Model with 2783M total params, 65M largest layer params.


key: _node_content
string_value:
{"id_": "d7d00077-490b-4bf0-b199-2359a19b95af", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "ad108758-e2a2-40b9-b153-f5a5a0697475", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "70048aeab2cf85c4a2ef3222682025cb5487e33765d7d51014cf0514fe83a30f", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "c1c2ff30-4ec1-4f7f-a800-1cee0c6654e8", "node_type": "1", "metadata": {}, "hash": "d426d2dbab6d384d3da2fd4eaae004d80281ba432f770744071b926c91a644de", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 1420, "end_char_idx": 4081, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
<Tip>

If you're having difficulties installing DeepSpeed, check the [DeepSpeed CUDA installation](../debugging#deepspeed-cuda-installation) guide. While DeepSpeed has a pip installable PyPI package, it is highly recommended to [install it from source](https://www.deepspeed.ai/tutorials/advanced-install/#install-deepspeed-from-source) to best match your hardware and to support certain features, like 1-bit Adam, which aren’t available in the PyPI distribution.

</Tip>

<hfoptions id="install">
<hfoption id="PyPI">

```bash
pip install deepspeed
```

</hfoption>
<hfoption id="Transformers">

```bash
pip install transformers[deepspeed]
```

</hfoption>
</hfoptions>

## Memory requirements

Before you begin, it is a good idea to check whether you have enough GPU and CPU memory to fit your model. DeepSpeed provides a tool for estimating the required CPU/GPU memory. For example, to estimate the memory requirements for the [bigscience/T0_3B](bigscience/T0_3B) model on a single GPU:

```bash
$ python -c 'from transformers import AutoModel; \
from deepspeed.runtime.zero.stage3 import estimate_zero3_model_states_mem_needs_all_live; \
model = AutoModel.from_pretrained("bigscience/T0_3B"); \
estimate_zero3_model_states_mem_needs_all_live(model, num_gpus_per_node=1, num_nodes=1)'
[...]
Estimated memory needed for params, optim states and gradients for a:
HW: Setup with 1 node, 1 GPU per node.
SW: Model with 2783M total params, 65M largest layer params.
  per CPU  |  per GPU |   Options
   70.00GB |   0.25GB | offload_param=cpu , offload_optimizer=cpu , zero_init=1
   70.00GB |   0.25GB | offload_param=cpu , offload_optimizer=cpu , zero_init=0
   62.23GB |   5.43GB | offload_param=none, offload_optimizer=cpu , zero_init=1
   62.23GB |   5.43GB | offload_param=none, offload_optimizer=cpu , zero_init=0
    0.37GB |  46.91GB | offload_param=none, offload_optimizer=none, zero_init=1
   15.56GB |  46.91GB | offload_param=none, offload_optimizer=none, zero_init=0
```

This means you either need a single 80GB GPU without CPU offload or a 8GB GPU and a ~60GB CPU to offload to (these are just the memory requirements for the parameters, optimizer states and gradients, and you'll need a bit more for the CUDA kernels and activations). You should also consider the tradeoff between cost and speed because it'll be cheaper to rent or buy a smaller GPU but it'll take longer to train your model.

If you have enough GPU memory make sure you disable CPU/NVMe offload to make everything faster.

## Select a ZeRO stage

After you've installed DeepSpeed and have a better idea of your memory requirements, the next step is selecting a ZeRO stage to use.


key: _node_content
string_value:
{"id_": "c1c2ff30-4ec1-4f7f-a800-1cee0c6654e8", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "d7d00077-490b-4bf0-b199-2359a19b95af", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "b150981335a86b1c4790af8ec50f9466994db4fdcff42904a6427d9cab93205b", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "b363427b-bd0a-4310-aacb-a1ac9ff7a22f", "node_type": "1", "metadata": {}, "hash": "20474397d829d08f4ff0fa535341607a156dc33dc7635e05ebd4f86163aa1664", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 2823, "end_char_idx": 5722, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
SW: Model with 2783M total params, 65M largest layer params.
  per CPU  |  per GPU |   Options
   70.00GB |   0.25GB | offload_param=cpu , offload_optimizer=cpu , zero_init=1
   70.00GB |   0.25GB | offload_param=cpu , offload_optimizer=cpu , zero_init=0
   62.23GB |   5.43GB | offload_param=none, offload_optimizer=cpu , zero_init=1
   62.23GB |   5.43GB | offload_param=none, offload_optimizer=cpu , zero_init=0
    0.37GB |  46.91GB | offload_param=none, offload_optimizer=none, zero_init=1
   15.56GB |  46.91GB | offload_param=none, offload_optimizer=none, zero_init=0
```

This means you either need a single 80GB GPU without CPU offload or a 8GB GPU and a ~60GB CPU to offload to (these are just the memory requirements for the parameters, optimizer states and gradients, and you'll need a bit more for the CUDA kernels and activations). You should also consider the tradeoff between cost and speed because it'll be cheaper to rent or buy a smaller GPU but it'll take longer to train your model.

If you have enough GPU memory make sure you disable CPU/NVMe offload to make everything faster.

## Select a ZeRO stage

After you've installed DeepSpeed and have a better idea of your memory requirements, the next step is selecting a ZeRO stage to use. In order of fastest and most memory-efficient:

| Fastest          | Memory efficient |
|------------------|------------------|
| ZeRO-1           | ZeRO-3 + offload |
| ZeRO-2           | ZeRO-3           |
| ZeRO-2 + offload | ZeRO-2 + offload |
| ZeRO-3           | ZeRO-2           |
| ZeRO-3 + offload | ZeRO-1           |

To find what works best for you, start with the fastest approach and if you run out of memory, try the next stage which is slower but more memory efficient. Feel free to work in whichever direction you prefer (starting with the most memory efficient or fastest) to discover the appropriate balance between speed and memory usage.

A general process you can use is (start with batch size of 1):

1. enable gradient checkpointing
2. try ZeRO-2
3. try ZeRO-2 and offload the optimizer
4. try ZeRO-3
5. try ZeRO-3 and offload parameters to the CPU
6. try ZeRO-3 and offload parameters and the optimizer to the CPU
7. try lowering various default values like a narrower search beam if you're using the [`~GenerationMixin.generate`] method
8. try mixed half-precision (fp16 on older GPU architectures and bf16 on Ampere) over full-precision weights
9. add more hardware if possible or enable Infinity to offload parameters and the optimizer to a NVMe
10. once you're not running out of memory, measure effective throughput and then try to increase the batch size as large as you can to maximize GPU efficiency
11. lastly, try to optimize your training setup by disabling some offload features or use a faster ZeRO stage and increasing/decreasing the batch size to find the best tradeoff between speed and memory usage


key: _node_content
string_value:
{"id_": "b363427b-bd0a-4310-aacb-a1ac9ff7a22f", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "c1c2ff30-4ec1-4f7f-a800-1cee0c6654e8", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "421b550240b8b636cc4c83210ddda91b43e6acab6007a3ef792cb3a62fc1c7c3", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "0f0e93b8-d535-445e-afad-7423100db430", "node_type": "1", "metadata": {}, "hash": "57c662e2d5b645555a19baa75f67d852ec634028cd166a6c796b28d19e0a6a19", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 4082, "end_char_idx": 7404, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
In order of fastest and most memory-efficient:

| Fastest          | Memory efficient |
|------------------|------------------|
| ZeRO-1           | ZeRO-3 + offload |
| ZeRO-2           | ZeRO-3           |
| ZeRO-2 + offload | ZeRO-2 + offload |
| ZeRO-3           | ZeRO-2           |
| ZeRO-3 + offload | ZeRO-1           |

To find what works best for you, start with the fastest approach and if you run out of memory, try the next stage which is slower but more memory efficient. Feel free to work in whichever direction you prefer (starting with the most memory efficient or fastest) to discover the appropriate balance between speed and memory usage.

A general process you can use is (start with batch size of 1):

1. enable gradient checkpointing
2. try ZeRO-2
3. try ZeRO-2 and offload the optimizer
4. try ZeRO-3
5. try ZeRO-3 and offload parameters to the CPU
6. try ZeRO-3 and offload parameters and the optimizer to the CPU
7. try lowering various default values like a narrower search beam if you're using the [`~GenerationMixin.generate`] method
8. try mixed half-precision (fp16 on older GPU architectures and bf16 on Ampere) over full-precision weights
9. add more hardware if possible or enable Infinity to offload parameters and the optimizer to a NVMe
10. once you're not running out of memory, measure effective throughput and then try to increase the batch size as large as you can to maximize GPU efficiency
11. lastly, try to optimize your training setup by disabling some offload features or use a faster ZeRO stage and increasing/decreasing the batch size to find the best tradeoff between speed and memory usage


## DeepSpeed configuration file

DeepSpeed works with the [`Trainer`] class by way of a config file containing all the parameters for configuring how you want setup your training run. When you execute your training script, DeepSpeed logs the configuration it received from [`Trainer`] to the console so you can see exactly what configuration was used.

<Tip>

Find a complete list of DeepSpeed configuration options on the [DeepSpeed Configuration JSON](https://www.deepspeed.ai/docs/config-json/) reference. You can also find more practical examples of various DeepSpeed configuration examples on the [DeepSpeedExamples](https://github.com/microsoft/DeepSpeedExamples) repository or the main [DeepSpeed](https://github.com/microsoft/DeepSpeed) repository. To quickly find specific examples, you can:

```bash
git clone https://github.com/microsoft/DeepSpeedExamples
cd DeepSpeedExamples
find . -name '*json'
# find examples with the Lamb optimizer
grep -i Lamb $(find . -name '*json')
```

</Tip>

The DeepSpeed configuration file is passed as a path to a JSON file if you're training from the command line interface or as a nested `dict` object if you're using the [`Trainer`] in a notebook setting.

<hfoptions id="pass-config">
<hfoption id="path to file">

```py
TrainingArguments(..., deepspeed="path/to/deepspeed_config.json")
```

</hfoption>
<hfoption id="nested dict">

```py
ds_config_dict = dict(scheduler=scheduler_params, optimizer=optimizer_params)
args = TrainingArguments(..., deepspeed=ds_config_dict)
trainer = Trainer(model, args, ...)
```

</hfoption>
</hfoptions>

### DeepSpeed and Trainer parameters

There are three types of configuration parameters:

1.


key: _node_content
string_value:
{"id_": "0f0e93b8-d535-445e-afad-7423100db430", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "b363427b-bd0a-4310-aacb-a1ac9ff7a22f", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "37a43302df8569b959e5693ffd140c0ab98e811cce35f7ad1191be0d5376fb1a", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "690afa49-cd42-40f4-822c-baef05576ddd", "node_type": "1", "metadata": {}, "hash": "6a484ff399c53116700d6212e3896df029a3b4418281542312ec2188cd9fe06b", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 5725, "end_char_idx": 9333, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
## DeepSpeed configuration file

DeepSpeed works with the [`Trainer`] class by way of a config file containing all the parameters for configuring how you want setup your training run. When you execute your training script, DeepSpeed logs the configuration it received from [`Trainer`] to the console so you can see exactly what configuration was used.

<Tip>

Find a complete list of DeepSpeed configuration options on the [DeepSpeed Configuration JSON](https://www.deepspeed.ai/docs/config-json/) reference. You can also find more practical examples of various DeepSpeed configuration examples on the [DeepSpeedExamples](https://github.com/microsoft/DeepSpeedExamples) repository or the main [DeepSpeed](https://github.com/microsoft/DeepSpeed) repository. To quickly find specific examples, you can:

```bash
git clone https://github.com/microsoft/DeepSpeedExamples
cd DeepSpeedExamples
find . -name '*json'
# find examples with the Lamb optimizer
grep -i Lamb $(find . -name '*json')
```

</Tip>

The DeepSpeed configuration file is passed as a path to a JSON file if you're training from the command line interface or as a nested `dict` object if you're using the [`Trainer`] in a notebook setting.

<hfoptions id="pass-config">
<hfoption id="path to file">

```py
TrainingArguments(..., deepspeed="path/to/deepspeed_config.json")
```

</hfoption>
<hfoption id="nested dict">

```py
ds_config_dict = dict(scheduler=scheduler_params, optimizer=optimizer_params)
args = TrainingArguments(..., deepspeed=ds_config_dict)
trainer = Trainer(model, args, ...)
```

</hfoption>
</hfoptions>

### DeepSpeed and Trainer parameters

There are three types of configuration parameters:

1. Some of the configuration parameters are shared by [`Trainer`] and DeepSpeed, and it can be difficult to identify errors when there are conflicting definitions. To make it easier, these shared configuration parameters are configured from the [`Trainer`] command line arguments.

2. Some configuration parameters that are automatically derived from the model configuration so you don't need to manually adjust these values. The [`Trainer`] uses a configuration value `auto` to determine set the most correct or efficient value. You could set your own configuration parameters explicitly, but you must take care to ensure the [`Trainer`] arguments and DeepSpeed configuration parameters agree. Mismatches may cause the training to fail in very difficult to detect ways!

3. Some configuration parameters specific to DeepSpeed only which need to be manually set based on your training needs.

You could also modify the DeepSpeed configuration and edit [`TrainingArguments`] from it:

1. Create or load a DeepSpeed configuration to use as the main configuration
2. Create a [`TrainingArguments`] object based on these DeepSpeed configuration values

Some values, such as `scheduler.params.total_num_steps` are calculated by the [`Trainer`] during training.

### ZeRO configuration

There are three configurations, each corresponding to a different ZeRO stage. Stage 1 is not as interesting for scalability, and this guide focuses on stages 2 and 3. The `zero_optimization` configuration contains all the options for what to enable and how to configure them. For a more detailed explanation of each parameter, take a look at the [DeepSpeed Configuration JSON](https://www.deepspeed.ai/docs/config-json/) reference.

<Tip warning={true}>
DeepSpeed doesn’t validate parameter names and any typos fallback on the parameter's default setting. You can watch the DeepSpeed engine startup log messages to see what values it is going to use.


key: _node_content
string_value:
{"id_": "690afa49-cd42-40f4-822c-baef05576ddd", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "0f0e93b8-d535-445e-afad-7423100db430", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "06e778890af2750ac0e57ca1baeb8b8bfd9d418def2ce28472fa09859e629b14", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "57571c98-8329-4405-b7eb-711ff32a28b1", "node_type": "1", "metadata": {}, "hash": "09dcc7ff68e9a762c1dc1aecd14cada7bd615151246ce5cb7319a6215f1b900e", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 7405, "end_char_idx": 10946, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
Some of the configuration parameters are shared by [`Trainer`] and DeepSpeed, and it can be difficult to identify errors when there are conflicting definitions. To make it easier, these shared configuration parameters are configured from the [`Trainer`] command line arguments.

2. Some configuration parameters that are automatically derived from the model configuration so you don't need to manually adjust these values. The [`Trainer`] uses a configuration value `auto` to determine set the most correct or efficient value. You could set your own configuration parameters explicitly, but you must take care to ensure the [`Trainer`] arguments and DeepSpeed configuration parameters agree. Mismatches may cause the training to fail in very difficult to detect ways!

3. Some configuration parameters specific to DeepSpeed only which need to be manually set based on your training needs.

You could also modify the DeepSpeed configuration and edit [`TrainingArguments`] from it:

1. Create or load a DeepSpeed configuration to use as the main configuration
2. Create a [`TrainingArguments`] object based on these DeepSpeed configuration values

Some values, such as `scheduler.params.total_num_steps` are calculated by the [`Trainer`] during training.

### ZeRO configuration

There are three configurations, each corresponding to a different ZeRO stage. Stage 1 is not as interesting for scalability, and this guide focuses on stages 2 and 3. The `zero_optimization` configuration contains all the options for what to enable and how to configure them. For a more detailed explanation of each parameter, take a look at the [DeepSpeed Configuration JSON](https://www.deepspeed.ai/docs/config-json/) reference.

<Tip warning={true}>
DeepSpeed doesn’t validate parameter names and any typos fallback on the parameter's default setting. You can watch the DeepSpeed engine startup log messages to see what values it is going to use.

</Tip>

The following configurations must be setup with DeepSpeed because the [`Trainer`] doesn't provide equivalent command line arguments.

<hfoptions id="zero-config">
<hfoption id="ZeRO-1">

ZeRO-1 shards the optimizer states across GPUs, and you can expect a tiny speed up. The ZeRO-1 config can be setup like this:

```yml
{
    "zero_optimization": {
        "stage": 1
    }
}
```

</hfoption>
<hfoption id="ZeRO-2">

ZeRO-2 shards the optimizer and gradients across GPUs. This stage is primarily used for training since its features are not relevant to inference. Some important parameters to configure for better performance include:

* `offload_optimizer` should be enabled to reduce GPU memory usage.
* `overlap_comm` when set to `true` trades off increased GPU memory usage to lower allreduce latency. This feature uses 4.5x the `allgather_bucket_size` and `reduce_bucket_size` values. In this example, they're set to `5e8` which means it requires 9GB of GPU memory. If your GPU memory is 8GB or less, you should reduce `overlap_comm` to lower the memory requirements and prevent an out-of-memory (OOM) error.
* `allgather_bucket_size` and `reduce_bucket_size` trade off available GPU memory for communication speed. The smaller their values, the slower communication is and the more GPU memory is available. You can balance, for example, whether a bigger batch size is more important than a slightly slower training time.
* `round_robin_gradients` is available in DeepSpeed 0.4.4 for CPU offloading. It parallelizes gradient copying to CPU memory among ranks by fine-grained gradient partitioning.


key: _node_content
string_value:
{"id_": "57571c98-8329-4405-b7eb-711ff32a28b1", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "690afa49-cd42-40f4-822c-baef05576ddd", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "db172b5dea48780ad5a998d5bb674942f9b2d424d0fe38063cc07f3a21cde1e3", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "2970f3a9-1fb4-4f5d-9dcf-b59dde68699a", "node_type": "1", "metadata": {}, "hash": "e622bce42177675c9ae72b30ef5c8a69e52438001d9a446e785044d319815e6e", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 9335, "end_char_idx": 12545, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
</Tip>

The following configurations must be setup with DeepSpeed because the [`Trainer`] doesn't provide equivalent command line arguments.

<hfoptions id="zero-config">
<hfoption id="ZeRO-1">

ZeRO-1 shards the optimizer states across GPUs, and you can expect a tiny speed up. The ZeRO-1 config can be setup like this:

```yml
{
    "zero_optimization": {
        "stage": 1
    }
}
```

</hfoption>
<hfoption id="ZeRO-2">

ZeRO-2 shards the optimizer and gradients across GPUs. This stage is primarily used for training since its features are not relevant to inference. Some important parameters to configure for better performance include:

* `offload_optimizer` should be enabled to reduce GPU memory usage.
* `overlap_comm` when set to `true` trades off increased GPU memory usage to lower allreduce latency. This feature uses 4.5x the `allgather_bucket_size` and `reduce_bucket_size` values. In this example, they're set to `5e8` which means it requires 9GB of GPU memory. If your GPU memory is 8GB or less, you should reduce `overlap_comm` to lower the memory requirements and prevent an out-of-memory (OOM) error.
* `allgather_bucket_size` and `reduce_bucket_size` trade off available GPU memory for communication speed. The smaller their values, the slower communication is and the more GPU memory is available. You can balance, for example, whether a bigger batch size is more important than a slightly slower training time.
* `round_robin_gradients` is available in DeepSpeed 0.4.4 for CPU offloading. It parallelizes gradient copying to CPU memory among ranks by fine-grained gradient partitioning. Performance benefit grows with gradient accumulation steps (more copying between optimizer steps) or GPU count (increased parallelism).

```yml
{
    "zero_optimization": {
        "stage": 2,
        "offload_optimizer": {
            "device": "cpu",
            "pin_memory": true
        },
        "allgather_partitions": true,
        "allgather_bucket_size": 5e8,
        "overlap_comm": true,
        "reduce_scatter": true,
        "reduce_bucket_size": 5e8,
        "contiguous_gradients": true
        "round_robin_gradients": true
    }
}
```

</hfoption>
<hfoption id="ZeRO-3">

ZeRO-3 shards the optimizer, gradient, and parameters across GPUs. Unlike ZeRO-2, ZeRO-3 can also be used for inference, in addition to training, because it allows large models to be loaded on multiple GPUs. Some important parameters to configure include:

* `device: "cpu"` can help if you're running out of GPU memory and if you have free CPU memory available. This allows offloading model parameters to the CPU.
* `pin_memory: true` can improve throughput, but less memory becomes available for other processes because the pinned memory is reserved for the specific process that requested it and it's typically accessed much faster than normal CPU memory.
* `stage3_max_live_parameters` is the upper limit on how many full parameters you want to keep on the GPU at any given time. Reduce this value if you encounter an OOM error.
* `stage3_max_reuse_distance` is a value for determining when a parameter is used again in the future, and it helps decide whether to throw the parameter away or to keep it.


key: _node_content
string_value:
{"id_": "2970f3a9-1fb4-4f5d-9dcf-b59dde68699a", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "57571c98-8329-4405-b7eb-711ff32a28b1", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "df907bcab579e5281fd4298f84b9f1c9ba730994b00a786c5f07948e55586ad7", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "c2a41ce6-21ce-43c0-b5d6-72926e18468a", "node_type": "1", "metadata": {}, "hash": "1fb4afe71567f903c105a1c70ed704cb3a5d504d30934b92f1179b12dc5d91c1", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 10849, "end_char_idx": 14209, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
It parallelizes gradient copying to CPU memory among ranks by fine-grained gradient partitioning. Performance benefit grows with gradient accumulation steps (more copying between optimizer steps) or GPU count (increased parallelism).

```yml
{
    "zero_optimization": {
        "stage": 2,
        "offload_optimizer": {
            "device": "cpu",
            "pin_memory": true
        },
        "allgather_partitions": true,
        "allgather_bucket_size": 5e8,
        "overlap_comm": true,
        "reduce_scatter": true,
        "reduce_bucket_size": 5e8,
        "contiguous_gradients": true
        "round_robin_gradients": true
    }
}
```

</hfoption>
<hfoption id="ZeRO-3">

ZeRO-3 shards the optimizer, gradient, and parameters across GPUs. Unlike ZeRO-2, ZeRO-3 can also be used for inference, in addition to training, because it allows large models to be loaded on multiple GPUs. Some important parameters to configure include:

* `device: "cpu"` can help if you're running out of GPU memory and if you have free CPU memory available. This allows offloading model parameters to the CPU.
* `pin_memory: true` can improve throughput, but less memory becomes available for other processes because the pinned memory is reserved for the specific process that requested it and it's typically accessed much faster than normal CPU memory.
* `stage3_max_live_parameters` is the upper limit on how many full parameters you want to keep on the GPU at any given time. Reduce this value if you encounter an OOM error.
* `stage3_max_reuse_distance` is a value for determining when a parameter is used again in the future, and it helps decide whether to throw the parameter away or to keep it. If the parameter is going to be reused (if the value is less than `stage3_max_reuse_distance`), then it is kept to reduce communication overhead. This is super helpful when activation checkpointing is enabled and you want to keep the parameter in the forward recompute until the backward pass. But reduce this value if you encounter an OOM error.
* `stage3_gather_16bit_weights_on_model_save` consolidates fp16 weights when a model is saved. For large models and multiple GPUs, this is expensive in terms of memory and speed. You should enable it if you're planning on resuming training.
* `sub_group_size` controls which parameters are updated during the optimizer step. Parameters are grouped into buckets of `sub_group_size` and each bucket is updated one at a time. When used with NVMe offload, `sub_group_size` determines when model states are moved in and out of CPU memory from during the optimization step. This prevents running out of CPU memory for extremely large models. `sub_group_size` can be left to its default value if you aren't using NVMe offload, but you may want to change it if you:

    1. Run into an OOM error during the optimizer step. In this case, reduce `sub_group_size` to reduce memory usage of the temporary buffers.
    2. The optimizer step is taking a really long time. In this case, increase `sub_group_size` to improve bandwidth utilization as a result of increased data buffers.

* `reduce_bucket_size`, `stage3_prefetch_bucket_size`, and `stage3_param_persistence_threshold` are dependent on a model's hidden size. It is recommended to set these values to `auto` and allow the [`Trainer`] to automatically assign the values.


key: _node_content
string_value:
{"id_": "c2a41ce6-21ce-43c0-b5d6-72926e18468a", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "2970f3a9-1fb4-4f5d-9dcf-b59dde68699a", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "ca9fbaa59d0b6d0f4155d0d2188fc72dd3ff77038e3b9615f31b7f06832e381c", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "400be75a-cc67-420e-9645-23e4959f0ecf", "node_type": "1", "metadata": {}, "hash": "4cecf0cf090bf952d33b283043aaeb74f4e5134be7d21b202cfb1b35592e6e66", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 12546, "end_char_idx": 15535, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
If the parameter is going to be reused (if the value is less than `stage3_max_reuse_distance`), then it is kept to reduce communication overhead. This is super helpful when activation checkpointing is enabled and you want to keep the parameter in the forward recompute until the backward pass. But reduce this value if you encounter an OOM error.
* `stage3_gather_16bit_weights_on_model_save` consolidates fp16 weights when a model is saved. For large models and multiple GPUs, this is expensive in terms of memory and speed. You should enable it if you're planning on resuming training.
* `sub_group_size` controls which parameters are updated during the optimizer step. Parameters are grouped into buckets of `sub_group_size` and each bucket is updated one at a time. When used with NVMe offload, `sub_group_size` determines when model states are moved in and out of CPU memory from during the optimization step. This prevents running out of CPU memory for extremely large models. `sub_group_size` can be left to its default value if you aren't using NVMe offload, but you may want to change it if you:

    1. Run into an OOM error during the optimizer step. In this case, reduce `sub_group_size` to reduce memory usage of the temporary buffers.
    2. The optimizer step is taking a really long time. In this case, increase `sub_group_size` to improve bandwidth utilization as a result of increased data buffers.

* `reduce_bucket_size`, `stage3_prefetch_bucket_size`, and `stage3_param_persistence_threshold` are dependent on a model's hidden size. It is recommended to set these values to `auto` and allow the [`Trainer`] to automatically assign the values.

```yml
{
    "zero_optimization": {
        "stage": 3,
        "offload_optimizer": {
            "device": "cpu",
            "pin_memory": true
        },
        "offload_param": {
            "device": "cpu",
            "pin_memory": true
        },
        "overlap_comm": true,
        "contiguous_gradients": true,
        "sub_group_size": 1e9,
        "reduce_bucket_size": "auto",
        "stage3_prefetch_bucket_size": "auto",
        "stage3_param_persistence_threshold": "auto",
        "stage3_max_live_parameters": 1e9,
        "stage3_max_reuse_distance": 1e9,
        "stage3_gather_16bit_weights_on_model_save": true
    }
}
```

You can use the [`deepspeed.zero.Init`](https://deepspeed.readthedocs.io/en/latest/zero3.html#deepspeed.zero.Init) context manager to initialize a model faster:

```py
from transformers import T5ForConditionalGeneration, T5Config
import deepspeed

with deepspeed.zero.Init():
    config = T5Config.from_pretrained("google-t5/t5-small")
    model = T5ForConditionalGeneration(config)
```

For pretrained models, the DeepSped config file needs to have `is_deepspeed_zero3_enabled: true` setup in [`TrainingArguments`] and it needs a ZeRO configuration enabled. The [`TrainingArguments`] object must be created **before** calling the model [`~PreTrainedModel.from_pretrained`].


key: _node_content
string_value:
{"id_": "400be75a-cc67-420e-9645-23e4959f0ecf", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "c2a41ce6-21ce-43c0-b5d6-72926e18468a", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "c8aab10fef9ac0e714148b7a47987dffd23e87222073763b3e4560b01d015e4c", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "921c0039-5005-4820-8738-015c504542ad", "node_type": "1", "metadata": {}, "hash": "25f10ff421ad9688a69ac27af21316983380f40eee7aa361b57494631fa64da0", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 13964, "end_char_idx": 17184, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
* `reduce_bucket_size`, `stage3_prefetch_bucket_size`, and `stage3_param_persistence_threshold` are dependent on a model's hidden size. It is recommended to set these values to `auto` and allow the [`Trainer`] to automatically assign the values.

```yml
{
    "zero_optimization": {
        "stage": 3,
        "offload_optimizer": {
            "device": "cpu",
            "pin_memory": true
        },
        "offload_param": {
            "device": "cpu",
            "pin_memory": true
        },
        "overlap_comm": true,
        "contiguous_gradients": true,
        "sub_group_size": 1e9,
        "reduce_bucket_size": "auto",
        "stage3_prefetch_bucket_size": "auto",
        "stage3_param_persistence_threshold": "auto",
        "stage3_max_live_parameters": 1e9,
        "stage3_max_reuse_distance": 1e9,
        "stage3_gather_16bit_weights_on_model_save": true
    }
}
```

You can use the [`deepspeed.zero.Init`](https://deepspeed.readthedocs.io/en/latest/zero3.html#deepspeed.zero.Init) context manager to initialize a model faster:

```py
from transformers import T5ForConditionalGeneration, T5Config
import deepspeed

with deepspeed.zero.Init():
    config = T5Config.from_pretrained("google-t5/t5-small")
    model = T5ForConditionalGeneration(config)
```

For pretrained models, the DeepSped config file needs to have `is_deepspeed_zero3_enabled: true` setup in [`TrainingArguments`] and it needs a ZeRO configuration enabled. The [`TrainingArguments`] object must be created **before** calling the model [`~PreTrainedModel.from_pretrained`].

```py
from transformers import AutoModel, Trainer, TrainingArguments

training_args = TrainingArguments(..., deepspeed=ds_config)
model = AutoModel.from_pretrained("google-t5/t5-small")
trainer = Trainer(model=model, args=training_args, ...)
```

You'll need ZeRO-3 if the fp16 weights don't fit on a single GPU. If you're able to load fp16 weights, then make sure you specify `torch_dtype=torch.float16` in [`~PreTrainedModel.from_pretrained`].

Another consideration for ZeRO-3 is if you have multiple GPUs, no single GPU has all the parameters unless it's the parameters for the currently executing layer. To access all parameters from all the layers at once, such as loading pretrained model weights in [`~PreTrainedModel.from_pretrained`], one layer is loaded at a time and immediately partitioned to all GPUs. This is because for very large models, it isn't possible to load the weights on one GPU and then distribute them across the other GPUs due to memory limitations.

If you encounter a model parameter weight that looks like the following, where `tensor([1.])` or the parameter size is 1 instead of a larger multi-dimensional shape, this means the parameter is partitioned and this is a ZeRO-3 placeholder.

```py
tensor([1.0], device="cuda:0", dtype=torch.float16, requires_grad=True)
```

<Tip>

For more information about initializing large models with ZeRO-3 and accessing the parameters, take a look at the [Constructing Massive Models](https://deepspeed.readthedocs.io/en/latest/zero3.html#constructing-massive-models) and [Gathering Parameters](https://deepspeed.readthedocs.io/en/latest/zero3.html#gathering-parameters) guides.


key: _node_content
string_value:
{"id_": "921c0039-5005-4820-8738-015c504542ad", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "400be75a-cc67-420e-9645-23e4959f0ecf", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "25e0da76fc757a373b79069f9e33643dbd512eb21fada8bc0078576366243979", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "871cb367-2013-4b80-826c-ffc3f7495344", "node_type": "1", "metadata": {}, "hash": "bae6a1593270c09387577b7670ea77ab58a0fb31389f96de838864646d942c9a", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 15537, "end_char_idx": 18485, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
```py
from transformers import AutoModel, Trainer, TrainingArguments

training_args = TrainingArguments(..., deepspeed=ds_config)
model = AutoModel.from_pretrained("google-t5/t5-small")
trainer = Trainer(model=model, args=training_args, ...)
```

You'll need ZeRO-3 if the fp16 weights don't fit on a single GPU. If you're able to load fp16 weights, then make sure you specify `torch_dtype=torch.float16` in [`~PreTrainedModel.from_pretrained`].

Another consideration for ZeRO-3 is if you have multiple GPUs, no single GPU has all the parameters unless it's the parameters for the currently executing layer. To access all parameters from all the layers at once, such as loading pretrained model weights in [`~PreTrainedModel.from_pretrained`], one layer is loaded at a time and immediately partitioned to all GPUs. This is because for very large models, it isn't possible to load the weights on one GPU and then distribute them across the other GPUs due to memory limitations.

If you encounter a model parameter weight that looks like the following, where `tensor([1.])` or the parameter size is 1 instead of a larger multi-dimensional shape, this means the parameter is partitioned and this is a ZeRO-3 placeholder.

```py
tensor([1.0], device="cuda:0", dtype=torch.float16, requires_grad=True)
```

<Tip>

For more information about initializing large models with ZeRO-3 and accessing the parameters, take a look at the [Constructing Massive Models](https://deepspeed.readthedocs.io/en/latest/zero3.html#constructing-massive-models) and [Gathering Parameters](https://deepspeed.readthedocs.io/en/latest/zero3.html#gathering-parameters) guides.

</Tip>

</hfoption>
</hfoptions>

### NVMe configuration

[ZeRO-Infinity](https://hf.co/papers/2104.07857) allows offloading model states to the CPU and/or NVMe to save even more memory. Smart partitioning and tiling algorithms allow each GPU to send and receive very small amounts of data during offloading such that a modern NVMe can fit an even larger total memory pool than is available to your training process. ZeRO-Infinity requires ZeRO-3.

Depending on the CPU and/or NVMe memory available, you can offload both the [optimizer states](https://www.deepspeed.ai/docs/config-json/#optimizer-offloading) and [parameters](https://www.deepspeed.ai/docs/config-json/#parameter-offloading), just one of them, or none. You should also make sure the `nvme_path` is pointing to an NVMe device, because while it still works with a normal hard drive or solid state drive, it'll be significantly slower. With a modern NVMe, you can expect peak transfer speeds of ~3.5GB/s for read and ~3GB/s for write operations. Lastly, [run a benchmark](https://github.com/microsoft/DeepSpeed/issues/998) on your training setup to determine the optimal `aio` configuration.

The example ZeRO-3/Infinity configuration file below sets most of the parameter values to `auto`, but you could also manually add these values.


key: _node_content
string_value:
{"id_": "871cb367-2013-4b80-826c-ffc3f7495344", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "921c0039-5005-4820-8738-015c504542ad", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "f2114963663082154408aff977d088d76861494b6d1f457222ac4340d111e5de", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "5a213fc0-fbc1-45bc-b249-cda996b33007", "node_type": "1", "metadata": {}, "hash": "d0ad19e32536166afaaebb7c0efb03d77c88bb33534ba2ee2707a5f15ba7b325", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 17186, "end_char_idx": 20541, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
</Tip>

</hfoption>
</hfoptions>

### NVMe configuration

[ZeRO-Infinity](https://hf.co/papers/2104.07857) allows offloading model states to the CPU and/or NVMe to save even more memory. Smart partitioning and tiling algorithms allow each GPU to send and receive very small amounts of data during offloading such that a modern NVMe can fit an even larger total memory pool than is available to your training process. ZeRO-Infinity requires ZeRO-3.

Depending on the CPU and/or NVMe memory available, you can offload both the [optimizer states](https://www.deepspeed.ai/docs/config-json/#optimizer-offloading) and [parameters](https://www.deepspeed.ai/docs/config-json/#parameter-offloading), just one of them, or none. You should also make sure the `nvme_path` is pointing to an NVMe device, because while it still works with a normal hard drive or solid state drive, it'll be significantly slower. With a modern NVMe, you can expect peak transfer speeds of ~3.5GB/s for read and ~3GB/s for write operations. Lastly, [run a benchmark](https://github.com/microsoft/DeepSpeed/issues/998) on your training setup to determine the optimal `aio` configuration.

The example ZeRO-3/Infinity configuration file below sets most of the parameter values to `auto`, but you could also manually add these values.

```yml
{
    "fp16": {
        "enabled": "auto",
        "loss_scale": 0,
        "loss_scale_window": 1000,
        "initial_scale_power": 16,
        "hysteresis": 2,
        "min_loss_scale": 1
    },

    "optimizer": {
        "type": "AdamW",
        "params": {
            "lr": "auto",
            "betas": "auto",
            "eps": "auto",
            "weight_decay": "auto"
        }
    },

    "scheduler": {
        "type": "WarmupLR",
        "params": {
            "warmup_min_lr": "auto",
            "warmup_max_lr": "auto",
            "warmup_num_steps": "auto"
        }
    },

    "zero_optimization": {
        "stage": 3,
        "offload_optimizer": {
            "device": "nvme",
            "nvme_path": "/local_nvme",
            "pin_memory": true,
            "buffer_count": 4,
            "fast_init": false
        },
        "offload_param": {
            "device": "nvme",
            "nvme_path": "/local_nvme",
            "pin_memory": true,
            "buffer_count": 5,
            "buffer_size": 1e8,
            "max_in_cpu": 1e9
        },
        "aio": {
            "block_size": 262144,
            "queue_depth": 32,
            "thread_count": 1,
            "single_submit": false,
            "overlap_events": true
        },
        "overlap_comm": true,
        "contiguous_gradients": true,
        "sub_group_size": 1e9,
        "reduce_bucket_size": "auto",
        "stage3_prefetch_bucket_size": "auto",
        "stage3_param_persistence_threshold": "auto",
        "stage3_max_live_parameters": 1e9,
        "stage3_max_reuse_distance": 1e9,
        "stage3_gather_16bit_weights_on_model_save": true
    },

    "gradient_accumulation_steps": "auto",
    "gradient_clipping": "auto",
    "steps_per_print": 2000,
    "train_batch_size": "auto",
    "train_micro_batch_size_per_gpu": "auto",
    "wall_clock_breakdown": false
}
```

## DeepSpeed features

There are a number of important parameters to specify in the DeepSpeed configuration file which are briefly described in this section.


key: _node_content
string_value:
{"id_": "5a213fc0-fbc1-45bc-b249-cda996b33007", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "871cb367-2013-4b80-826c-ffc3f7495344", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "db28441c6e730e06ac2b06bb31c92ceea2bc4ed0b4ac5c876dafc1af9b96e0cf", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "f41af833-5710-46a3-a694-e1480df3a1bc", "node_type": "1", "metadata": {}, "hash": "f61da2562c3fc580e05e27938d999e344cfb0e3768042539cf5b106e62452d0a", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 20543, "end_char_idx": 23457, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
### Activation/gradient checkpointing

Activation and gradient checkpointing trades speed for more GPU memory which allows you to overcome scenarios where your GPU is out of memory or to increase your batch size for better performance. To enable this feature:

1. For a Hugging Face model, set `model.gradient_checkpointing_enable()` or `--gradient_checkpointing` in the [`Trainer`].
2. For a non-Hugging Face model, use the DeepSpeed [Activation Checkpointing API](https://deepspeed.readthedocs.io/en/latest/activation-checkpointing.html). You could also replace the Transformers modeling code and replace `torch.utils.checkpoint` with the DeepSpeed API. This approach is more flexible because you can offload the forward activations to the CPU memory instead of recalculating them.

### Optimizer and scheduler

DeepSpeed and Transformers optimizer and scheduler can be mixed and matched as long as you don't enable `offload_optimizer`. When `offload_optimizer` is enabled, you could use a non-DeepSpeed optimizer (except for LAMB) as long as it has both a CPU and GPU implementation.

<Tip warning={true}>

The optimizer and scheduler parameters for the config file can be set from the command line to avoid hard to find errors. For example, if the learning rate is set to a different value in another place you can override it from the command line. Aside from the optimizer and scheduler parameters, you'll need to ensure your [`Trainer`] command line arguments match the DeepSpeed configuration.

</Tip>

<hfoptions id="opt-sched">
<hfoption id="optimizer">

DeepSpeed offers several [optimizers](https://www.deepspeed.ai/docs/config-json/#optimizer-parameters) (Adam, AdamW, OneBitAdam, and LAMB) but you can also import other optimizers from PyTorch. If you don't configure the optimizer in the config, the [`Trainer`] automatically selects AdamW and either uses the supplied values or the default values for the following parameters from the command line: `lr`, `adam_beta1`, `adam_beta2`, `adam_epsilon`, `weight_decay`.

You can set the parameters to `"auto"` or manually input your own desired values.

```yaml
{
   "optimizer": {
       "type": "AdamW",
       "params": {
         "lr": "auto",
         "betas": "auto",
         "eps": "auto",
         "weight_decay": "auto"
       }
   }
}
```

You can also use an unsupported optimizer by adding the following to the top level configuration.

```yaml
{
   "zero_allow_untested_optimizer": true
}
```

From DeepSpeed==0.8.3 on, if you want to use offload, you'll also need to the following to the top level configuration because offload works best with DeepSpeed's CPU Adam optimizer.

```yaml
{
   "zero_force_ds_cpu_optimizer": false
}
```

</hfoption>
<hfoption id="scheduler">

DeepSpeed supports the LRRangeTest, OneCycle, WarmupLR and WarmupDecayLR learning rate [schedulers](https://www.deepspeed.ai/docs/config-json/#scheduler-parameters).


key: _node_content
string_value:
{"id_": "f41af833-5710-46a3-a694-e1480df3a1bc", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "5a213fc0-fbc1-45bc-b249-cda996b33007", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "19066e756ee402b09881587be0d7b77013e2ede541853c46134182051f8b035a", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "e40ed3c3-0882-4ee6-a5ee-d3aa8b39c8fe", "node_type": "1", "metadata": {}, "hash": "6157b46c7ac0d7a4fb4c6baf996d039d338e36630066789becda8eb83bd070b6", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 21897, "end_char_idx": 24877, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
Aside from the optimizer and scheduler parameters, you'll need to ensure your [`Trainer`] command line arguments match the DeepSpeed configuration.

</Tip>

<hfoptions id="opt-sched">
<hfoption id="optimizer">

DeepSpeed offers several [optimizers](https://www.deepspeed.ai/docs/config-json/#optimizer-parameters) (Adam, AdamW, OneBitAdam, and LAMB) but you can also import other optimizers from PyTorch. If you don't configure the optimizer in the config, the [`Trainer`] automatically selects AdamW and either uses the supplied values or the default values for the following parameters from the command line: `lr`, `adam_beta1`, `adam_beta2`, `adam_epsilon`, `weight_decay`.

You can set the parameters to `"auto"` or manually input your own desired values.

```yaml
{
   "optimizer": {
       "type": "AdamW",
       "params": {
         "lr": "auto",
         "betas": "auto",
         "eps": "auto",
         "weight_decay": "auto"
       }
   }
}
```

You can also use an unsupported optimizer by adding the following to the top level configuration.

```yaml
{
   "zero_allow_untested_optimizer": true
}
```

From DeepSpeed==0.8.3 on, if you want to use offload, you'll also need to the following to the top level configuration because offload works best with DeepSpeed's CPU Adam optimizer.

```yaml
{
   "zero_force_ds_cpu_optimizer": false
}
```

</hfoption>
<hfoption id="scheduler">

DeepSpeed supports the LRRangeTest, OneCycle, WarmupLR and WarmupDecayLR learning rate [schedulers](https://www.deepspeed.ai/docs/config-json/#scheduler-parameters).

Transformers and DeepSpeed provide two of the same schedulers:

* WarmupLR is the same as `--lr_scheduler_type constant_with_warmup` in Transformers
* WarmupDecayLR is the same as  `--lr_scheduler_type linear` in Transformers (this is the default scheduler used in Transformers)

If you don't configure the scheduler in the config, the [`Trainer`] automatically selects WarmupDecayLR and either uses the supplied values or the default values for the following parameters from the command line: `warmup_min_lr`, `warmup_max_lr`, `warmup_num_steps`, `total_num_steps` (automatically calculated during run time if `max_steps` is not provided).

You can set the parameters to `"auto"` or manually input your own desired values.

```yaml
{
   "scheduler": {
         "type": "WarmupDecayLR",
         "params": {
             "total_num_steps": "auto",
             "warmup_min_lr": "auto",
             "warmup_max_lr": "auto",
             "warmup_num_steps": "auto"
         }
     }
}
```

</hfoption>
</hfoptions>

### Precision

Deepspeed supports fp32, fp16, and bf16 mixed precision.

<hfoptions id="precision">
<hfoption id="fp32">

If your model doesn't work well with mixed precision, for example if it wasn't pretrained in mixed precision, you may encounter overflow or underflow issues which can cause NaN loss. For these cases, you should use full fp32 precision by explicitly disabling the default fp16 mode.


key: _node_content
string_value:
{"id_": "e40ed3c3-0882-4ee6-a5ee-d3aa8b39c8fe", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "f41af833-5710-46a3-a694-e1480df3a1bc", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "71e09de0644f1a8cd4b9c61fc21b370de2afe929abe47dfe7c91730357f7800a", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "43de3e67-158c-4e9b-8ad6-dfdb6b45c41d", "node_type": "1", "metadata": {}, "hash": "52a70a2b2daf4af82290a537120db619cd73c142ccf1b14b8aad6461254731c5", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 23459, "end_char_idx": 26459, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
Transformers and DeepSpeed provide two of the same schedulers:

* WarmupLR is the same as `--lr_scheduler_type constant_with_warmup` in Transformers
* WarmupDecayLR is the same as  `--lr_scheduler_type linear` in Transformers (this is the default scheduler used in Transformers)

If you don't configure the scheduler in the config, the [`Trainer`] automatically selects WarmupDecayLR and either uses the supplied values or the default values for the following parameters from the command line: `warmup_min_lr`, `warmup_max_lr`, `warmup_num_steps`, `total_num_steps` (automatically calculated during run time if `max_steps` is not provided).

You can set the parameters to `"auto"` or manually input your own desired values.

```yaml
{
   "scheduler": {
         "type": "WarmupDecayLR",
         "params": {
             "total_num_steps": "auto",
             "warmup_min_lr": "auto",
             "warmup_max_lr": "auto",
             "warmup_num_steps": "auto"
         }
     }
}
```

</hfoption>
</hfoptions>

### Precision

Deepspeed supports fp32, fp16, and bf16 mixed precision.

<hfoptions id="precision">
<hfoption id="fp32">

If your model doesn't work well with mixed precision, for example if it wasn't pretrained in mixed precision, you may encounter overflow or underflow issues which can cause NaN loss. For these cases, you should use full fp32 precision by explicitly disabling the default fp16 mode.

```yaml
{
    "fp16": {
        "enabled": false
    }
}
```

For Ampere GPUs and PyTorch > 1.7, it automatically switches to the more efficient [tf32](https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices) format for some operations but the results are still in fp32. You can control it from the [`Trainer`] by setting `--tf32` to enable it, and `--tf32 0` or `--no_tf32` to disable it.

</hfoption>
<hfoption id="fp16">

To configure PyTorch AMP-like fp16 mixed precision reduces memory usage and accelerates training speed. [`Trainer`] automatically enables or disables fp16 based on the value of `args.fp16_backend`, and the rest of the config can be set by you. fp16 is enabled from the command line when the following arguments are passed: `--fp16`, `--fp16_backend amp` or `--fp16_full_eval`.

```yaml
{
    "fp16": {
        "enabled": "auto",
        "loss_scale": 0,
        "loss_scale_window": 1000,
        "initial_scale_power": 16,
        "hysteresis": 2,
        "min_loss_scale": 1
    }
}
```

For additional DeepSpeed fp16 training options, take a look at the [FP16 Training Options](https://www.deepspeed.ai/docs/config-json/#fp16-training-options) reference.

To configure Apex-like fp16 mixed precision, setup the config as shown below with `"auto"` or your own values. [`Trainer`] automatically configure `amp` based on the values of `args.fp16_backend` and `args.fp16_opt_level`. It can also be enabled from the command line when the following arguments are passed: `--fp16`, `--fp16_backend apex` or `--fp16_opt_level 01`.


key: _node_content
string_value:
{"id_": "43de3e67-158c-4e9b-8ad6-dfdb6b45c41d", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "e40ed3c3-0882-4ee6-a5ee-d3aa8b39c8fe", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "f9ca4a2a3a72331c41025fab4cbf5613ed5f8d0a4aeba6224ff36b518d5c2484", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "3c21e308-0af4-42cb-8c12-8b8e828bf5cb", "node_type": "1", "metadata": {}, "hash": "00d03e2729c3b10f3482d59bccd16eec56cbeece104fad2ed83a5d018a6821b5", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 25180, "end_char_idx": 28218, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
You can control it from the [`Trainer`] by setting `--tf32` to enable it, and `--tf32 0` or `--no_tf32` to disable it.

</hfoption>
<hfoption id="fp16">

To configure PyTorch AMP-like fp16 mixed precision reduces memory usage and accelerates training speed. [`Trainer`] automatically enables or disables fp16 based on the value of `args.fp16_backend`, and the rest of the config can be set by you. fp16 is enabled from the command line when the following arguments are passed: `--fp16`, `--fp16_backend amp` or `--fp16_full_eval`.

```yaml
{
    "fp16": {
        "enabled": "auto",
        "loss_scale": 0,
        "loss_scale_window": 1000,
        "initial_scale_power": 16,
        "hysteresis": 2,
        "min_loss_scale": 1
    }
}
```

For additional DeepSpeed fp16 training options, take a look at the [FP16 Training Options](https://www.deepspeed.ai/docs/config-json/#fp16-training-options) reference.

To configure Apex-like fp16 mixed precision, setup the config as shown below with `"auto"` or your own values. [`Trainer`] automatically configure `amp` based on the values of `args.fp16_backend` and `args.fp16_opt_level`. It can also be enabled from the command line when the following arguments are passed: `--fp16`, `--fp16_backend apex` or `--fp16_opt_level 01`.

```yaml
{
    "amp": {
        "enabled": "auto",
        "opt_level": "auto"
    }
}
```

</hfoption>
<hfoption id="bf16">

To use bf16, you'll need at least DeepSpeed==0.6.0. bf16 has the same dynamic range as fp32 and doesn’t require loss scaling. However, if you use [gradient accumulation](#gradient-accumulation) with bf16, gradients are accumulated in bf16 which may not be desired because this format's low precision can lead to lossy accumulation.

bf16 can be setup in the config file or enabled from the command line when the following arguments are passed: `--bf16` or `--bf16_full_eval`.

```yaml
{
    "bf16": {
        "enabled": "auto"
    }
}
```

</hfoption>
</hfoptions>

### Batch size

The batch size can be auto-configured or explicitly set. If you choose to use the `"auto"` option, [`Trainer`] sets `train_micro_batch_size_per_gpu` to the value of args.`per_device_train_batch_size` and `train_batch_size` to `args.world_size * args.per_device_train_batch_size * args.gradient_accumulation_steps`.

```yaml
{
    "train_micro_batch_size_per_gpu": "auto",
    "train_batch_size": "auto"
}
```

### Gradient accumulation

Gradient accumulation can be auto-configured or explicitly set. If you choose to use the `"auto"` option, [`Trainer`] sets it to the value of `args.gradient_accumulation_steps`.

```yaml
{
    "gradient_accumulation_steps": "auto"
}

```

### Gradient clipping

Gradient clipping can be auto-configured or explicitly set. If you choose to use the `"auto"` option, [`Trainer`] sets it to the value of `args.max_grad_norm`.

```yaml
{
    "gradient_clipping": "auto"
}
```

### Communication data type

For communication collectives like reduction, gathering and scattering operations, a separate data type is used.


key: _node_content
string_value:
{"id_": "3c21e308-0af4-42cb-8c12-8b8e828bf5cb", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "43de3e67-158c-4e9b-8ad6-dfdb6b45c41d", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "1ea8faa7c3277b545e86cef4e9105c6f432ad90fdedb6c084a37b910041a8a2a", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "c737af41-c062-4151-afc6-bf1873c41331", "node_type": "1", "metadata": {}, "hash": "ee5ca824608638ebfc9b08113de83051a2fe34d9c4b6ef203cd30619184d2f5c", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 26638, "end_char_idx": 29889, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
bf16 has the same dynamic range as fp32 and doesn’t require loss scaling. However, if you use [gradient accumulation](#gradient-accumulation) with bf16, gradients are accumulated in bf16 which may not be desired because this format's low precision can lead to lossy accumulation.

bf16 can be setup in the config file or enabled from the command line when the following arguments are passed: `--bf16` or `--bf16_full_eval`.

```yaml
{
    "bf16": {
        "enabled": "auto"
    }
}
```

</hfoption>
</hfoptions>

### Batch size

The batch size can be auto-configured or explicitly set. If you choose to use the `"auto"` option, [`Trainer`] sets `train_micro_batch_size_per_gpu` to the value of args.`per_device_train_batch_size` and `train_batch_size` to `args.world_size * args.per_device_train_batch_size * args.gradient_accumulation_steps`.

```yaml
{
    "train_micro_batch_size_per_gpu": "auto",
    "train_batch_size": "auto"
}
```

### Gradient accumulation

Gradient accumulation can be auto-configured or explicitly set. If you choose to use the `"auto"` option, [`Trainer`] sets it to the value of `args.gradient_accumulation_steps`.

```yaml
{
    "gradient_accumulation_steps": "auto"
}

```

### Gradient clipping

Gradient clipping can be auto-configured or explicitly set. If you choose to use the `"auto"` option, [`Trainer`] sets it to the value of `args.max_grad_norm`.

```yaml
{
    "gradient_clipping": "auto"
}
```

### Communication data type

For communication collectives like reduction, gathering and scattering operations, a separate data type is used.

All gather and scatter operations are performed in the same data type the data is in. For example, if you're training with bf16, the data is also gathered in bf16 because gathering is a non-lossy operation.

Reduce operations are lossy, for example when gradients are averaged across multiple GPUs. When the communication is done in fp16 or bf16, it is more likely to be lossy because adding multiple numbers in low precision isn't exact. This is especially the case with bf16 which has a lower precision than fp16. For this reason, fp16 is the default for reduction operations because the loss is minimal when averaging gradients.

You can choose the communication data type by setting the `communication_data_type` parameter in the config file. For example, choosing fp32 adds a small amount of overhead but ensures the reduction operation is accumulated in fp32 and when it is ready, it is downcasted to whichever half-precision dtype you're training in.

```yaml
{
    "communication_data_type": "fp32"
}
```

## Deployment

DeepSpeed can be deployed by different launchers such as [torchrun](https://pytorch.org/docs/stable/elastic/run.html), the `deepspeed` launcher, or [Accelerate](https://huggingface.co/docs/accelerate/basic_tutorials/launch#using-accelerate-launch). To deploy, add `--deepspeed ds_config.json` to the [`Trainer`] command line. It’s recommended to use DeepSpeed’s [`add_config_arguments`](https://deepspeed.readthedocs.io/en/latest/initialize.html#argument-parsing) utility to add any necessary command line arguments to your code.

This guide will show you how to deploy DeepSpeed with the `deepspeed` launcher for different training setups.


key: _node_content
string_value:
{"id_": "c737af41-c062-4151-afc6-bf1873c41331", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "3c21e308-0af4-42cb-8c12-8b8e828bf5cb", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "c7c941f98fad4062367318c0c67fbda34bf42dd4fd120608ca55b8974a72425c", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "b6a204ac-4b55-4743-b613-238ac1579114", "node_type": "1", "metadata": {}, "hash": "b5ddc7f78eac095e2e047f5704896e9394510728b35efb14e9141b850a54fe8d", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 28220, "end_char_idx": 31385, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
All gather and scatter operations are performed in the same data type the data is in. For example, if you're training with bf16, the data is also gathered in bf16 because gathering is a non-lossy operation.

Reduce operations are lossy, for example when gradients are averaged across multiple GPUs. When the communication is done in fp16 or bf16, it is more likely to be lossy because adding multiple numbers in low precision isn't exact. This is especially the case with bf16 which has a lower precision than fp16. For this reason, fp16 is the default for reduction operations because the loss is minimal when averaging gradients.

You can choose the communication data type by setting the `communication_data_type` parameter in the config file. For example, choosing fp32 adds a small amount of overhead but ensures the reduction operation is accumulated in fp32 and when it is ready, it is downcasted to whichever half-precision dtype you're training in.

```yaml
{
    "communication_data_type": "fp32"
}
```

## Deployment

DeepSpeed can be deployed by different launchers such as [torchrun](https://pytorch.org/docs/stable/elastic/run.html), the `deepspeed` launcher, or [Accelerate](https://huggingface.co/docs/accelerate/basic_tutorials/launch#using-accelerate-launch). To deploy, add `--deepspeed ds_config.json` to the [`Trainer`] command line. It’s recommended to use DeepSpeed’s [`add_config_arguments`](https://deepspeed.readthedocs.io/en/latest/initialize.html#argument-parsing) utility to add any necessary command line arguments to your code.

This guide will show you how to deploy DeepSpeed with the `deepspeed` launcher for different training setups. You can check out this [post](https://github.com/huggingface/transformers/issues/8771#issuecomment-759248400) for more practical usage examples.


<hfoptions id="deploy">
<hfoption id="multi-GPU">

To deploy DeepSpeed on multiple GPUs, add the `--num_gpus` parameter. If you want to use all available GPUs, you don't need to add `--num_gpus`. The example below uses 2 GPUs.

```bash
deepspeed --num_gpus=2 examples/pytorch/translation/run_translation.py \
--deepspeed tests/deepspeed/ds_config_zero3.json \
--model_name_or_path google-t5/t5-small --per_device_train_batch_size 1 \
--output_dir output_dir --overwrite_output_dir --fp16 \
--do_train --max_train_samples 500 --num_train_epochs 1 \
--dataset_name wmt16 --dataset_config "ro-en" \
--source_lang en --target_lang ro
```

</hfoption>
<hfoption id="single-GPU">

To deploy DeepSpeed on a single GPU, add the `--num_gpus` parameter. It isn't necessary to explicitly set this value if you only have 1 GPU because DeepSpeed deploys all GPUs it can see on a given node.

```bash
deepspeed --num_gpus=1 examples/pytorch/translation/run_translation.py \
--deepspeed tests/deepspeed/ds_config_zero2.json \
--model_name_or_path google-t5/t5-small --per_device_train_batch_size 1 \
--output_dir output_dir --overwrite_output_dir --fp16 \
--do_train --max_train_samples 500 --num_train_epochs 1 \
--dataset_name wmt16 --dataset_config "ro-en" \
--source_lang en --target_lang ro
```

DeepSpeed is still useful with just 1 GPU because you can:

1.


key: _node_content
string_value:
{"id_": "b6a204ac-4b55-4743-b613-238ac1579114", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "c737af41-c062-4151-afc6-bf1873c41331", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "5c14704d6ec4c7aa61326d246d0f4e0d2648dd40b187396b9a7f9e8d893233f7", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "0dab27f9-44ea-4d0c-b012-dcd757ab3ac6", "node_type": "1", "metadata": {}, "hash": "8400c1488b6c431fafc961f08640f129123276ea18f01ef5fe314bd62733e3c1", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 30037, "end_char_idx": 33159, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
<hfoptions id="deploy">
<hfoption id="multi-GPU">

To deploy DeepSpeed on multiple GPUs, add the `--num_gpus` parameter. If you want to use all available GPUs, you don't need to add `--num_gpus`. The example below uses 2 GPUs.

```bash
deepspeed --num_gpus=2 examples/pytorch/translation/run_translation.py \
--deepspeed tests/deepspeed/ds_config_zero3.json \
--model_name_or_path google-t5/t5-small --per_device_train_batch_size 1 \
--output_dir output_dir --overwrite_output_dir --fp16 \
--do_train --max_train_samples 500 --num_train_epochs 1 \
--dataset_name wmt16 --dataset_config "ro-en" \
--source_lang en --target_lang ro
```

</hfoption>
<hfoption id="single-GPU">

To deploy DeepSpeed on a single GPU, add the `--num_gpus` parameter. It isn't necessary to explicitly set this value if you only have 1 GPU because DeepSpeed deploys all GPUs it can see on a given node.

```bash
deepspeed --num_gpus=1 examples/pytorch/translation/run_translation.py \
--deepspeed tests/deepspeed/ds_config_zero2.json \
--model_name_or_path google-t5/t5-small --per_device_train_batch_size 1 \
--output_dir output_dir --overwrite_output_dir --fp16 \
--do_train --max_train_samples 500 --num_train_epochs 1 \
--dataset_name wmt16 --dataset_config "ro-en" \
--source_lang en --target_lang ro
```

DeepSpeed is still useful with just 1 GPU because you can:

1. Offload some computations and memory to the CPU to make more GPU resources available to your model to use a larger batch size or fit a very large model that normally won't fit.
2. Minimize memory fragmentation with it's smart GPU memory management system which also allows you to fit bigger models and data batches.

<Tip>

Set the `allgather_bucket_size` and `reduce_bucket_size` values to 2e8 in the [ZeRO-2](#zero-configuration) configuration file to get better performance on a single GPU.

</Tip>

</hfoption>
</hfoptions>

### Multi-node deployment

A node is one or more GPUs for running a workload. A more powerful setup is a multi-node setup which can be launched with the `deepspeed` launcher. For this guide, let's assume there are two nodes with 8 GPUs each. The first node can be accessed `ssh hostname1` and the second node with `ssh hostname2`. Both nodes must be able to communicate with each other locally over ssh without a password.

By default, DeepSpeed expects your multi-node environment to use a shared storage. If this is not the case and each node can only see the local filesystem, you need to adjust the config file to include a [`checkpoint`](https://www.deepspeed.ai/docs/config-json/#checkpoint-options) to allow loading without access to a shared filesystem:

```yaml
{
  "checkpoint": {
    "use_node_local_storage": true
  }
}
```

You could also use the [`Trainer`]'s `--save_on_each_node` argument to automatically add the above `checkpoint` to your config.

<hfoptions id="multinode">
<hfoption id="torchrun">

For [torchrun](https://pytorch.org/docs/stable/elastic/run.html), you have to ssh to each node and run the following command on both of them. The launcher waits until both nodes are synchronized before launching the training.


key: _node_content
string_value:
{"id_": "0dab27f9-44ea-4d0c-b012-dcd757ab3ac6", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "b6a204ac-4b55-4743-b613-238ac1579114", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "c18d650e62ebb7703dd4f1e9384d0f77ce5383b6160343df5b6e649617af5e10", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "bf1a66e0-7f6d-4a8c-980c-ce13523617ee", "node_type": "1", "metadata": {}, "hash": "6700ab39d5b5a7bf4cb4580fc20616a9a663fb33e6871c17725f4588b307e8d8", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 31563, "end_char_idx": 34355, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
2. Minimize memory fragmentation with it's smart GPU memory management system which also allows you to fit bigger models and data batches.

<Tip>

Set the `allgather_bucket_size` and `reduce_bucket_size` values to 2e8 in the [ZeRO-2](#zero-configuration) configuration file to get better performance on a single GPU.

</Tip>

</hfoption>
</hfoptions>

### Multi-node deployment

A node is one or more GPUs for running a workload. A more powerful setup is a multi-node setup which can be launched with the `deepspeed` launcher. For this guide, let's assume there are two nodes with 8 GPUs each. The first node can be accessed `ssh hostname1` and the second node with `ssh hostname2`. Both nodes must be able to communicate with each other locally over ssh without a password.

By default, DeepSpeed expects your multi-node environment to use a shared storage. If this is not the case and each node can only see the local filesystem, you need to adjust the config file to include a [`checkpoint`](https://www.deepspeed.ai/docs/config-json/#checkpoint-options) to allow loading without access to a shared filesystem:

```yaml
{
  "checkpoint": {
    "use_node_local_storage": true
  }
}
```

You could also use the [`Trainer`]'s `--save_on_each_node` argument to automatically add the above `checkpoint` to your config.

<hfoptions id="multinode">
<hfoption id="torchrun">

For [torchrun](https://pytorch.org/docs/stable/elastic/run.html), you have to ssh to each node and run the following command on both of them. The launcher waits until both nodes are synchronized before launching the training.

```bash
torchrun --nproc_per_node=8 --nnode=2 --node_rank=0 --master_addr=hostname1 \
--master_port=9901 your_program.py <normal cl args> --deepspeed ds_config.json
```

</hfoption>
<hfoption id="deepspeed">

For the `deepspeed` launcher, start by creating a `hostfile`.

```bash
hostname1 slots=8
hostname2 slots=8
```

Then you can launch the training with the following command. The `deepspeed` launcher automatically launches the command on both nodes at once.

```bash
deepspeed --num_gpus 8 --num_nodes 2 --hostfile hostfile --master_addr hostname1 --master_port=9901 \
your_program.py <normal cl args> --deepspeed ds_config.json
```

Check out the [Resource Configuration (multi-node)](https://www.deepspeed.ai/getting-started/#resource-configuration-multi-node) guide for more details about configuring multi-node compute resources.

</hfoption>
</hfoptions>

### SLURM

In a SLURM environment, you'll need to adapt your SLURM script to your specific SLURM environment. An example SLURM script may look like:

```bash
#SBATCH --job-name=test-nodes        # name
#SBATCH --nodes=2                    # nodes
#SBATCH --ntasks-per-node=1          # crucial - only 1 task per dist per node!


key: _node_content
string_value:
{"id_": "bf1a66e0-7f6d-4a8c-980c-ce13523617ee", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "0dab27f9-44ea-4d0c-b012-dcd757ab3ac6", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "296c6e8ad2acc201df97c364b853275479b0269e2e34c1f56bb4d6e257d3fd6f", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "ed8442fd-4d08-45c8-be48-714b9579b9d4", "node_type": "1", "metadata": {}, "hash": "b6645005c21e1286b0082b2671cdad41dcffc1fd27e1beeb5059d991e6120c12", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 32881, "end_char_idx": 35623, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
<hfoptions id="multinode">
<hfoption id="torchrun">

For [torchrun](https://pytorch.org/docs/stable/elastic/run.html), you have to ssh to each node and run the following command on both of them. The launcher waits until both nodes are synchronized before launching the training.

```bash
torchrun --nproc_per_node=8 --nnode=2 --node_rank=0 --master_addr=hostname1 \
--master_port=9901 your_program.py <normal cl args> --deepspeed ds_config.json
```

</hfoption>
<hfoption id="deepspeed">

For the `deepspeed` launcher, start by creating a `hostfile`.

```bash
hostname1 slots=8
hostname2 slots=8
```

Then you can launch the training with the following command. The `deepspeed` launcher automatically launches the command on both nodes at once.

```bash
deepspeed --num_gpus 8 --num_nodes 2 --hostfile hostfile --master_addr hostname1 --master_port=9901 \
your_program.py <normal cl args> --deepspeed ds_config.json
```

Check out the [Resource Configuration (multi-node)](https://www.deepspeed.ai/getting-started/#resource-configuration-multi-node) guide for more details about configuring multi-node compute resources.

</hfoption>
</hfoptions>

### SLURM

In a SLURM environment, you'll need to adapt your SLURM script to your specific SLURM environment. An example SLURM script may look like:

```bash
#SBATCH --job-name=test-nodes        # name
#SBATCH --nodes=2                    # nodes
#SBATCH --ntasks-per-node=1          # crucial - only 1 task per dist per node!
#SBATCH --cpus-per-task=10           # number of cores per tasks
#SBATCH --gres=gpu:8                 # number of gpus
#SBATCH --time 20:00:00              # maximum execution time (HH:MM:SS)
#SBATCH --output=%x-%j.out           # output file name

export GPUS_PER_NODE=8
export MASTER_ADDR=$(scontrol show hostnames $SLURM_JOB_NODELIST | head -n 1)
export MASTER_PORT=9901

srun --jobid $SLURM_JOBID bash -c 'python -m torch.distributed.run \
 --nproc_per_node $GPUS_PER_NODE --nnodes $SLURM_NNODES --node_rank $SLURM_PROCID \
 --master_addr $MASTER_ADDR --master_port $MASTER_PORT \
your_program.py <normal cl args> --deepspeed ds_config.json'
```

Then you can schedule your multi-node deployment with the following command which launches training simultaneously on all nodes.

```bash
sbatch launch.slurm
```

### Notebook

The `deepspeed` launcher doesn't support deployment from a notebook so you'll need to emulate the distributed environment. However, this only works for 1 GPU. If you want to use more than 1 GPU, you must use a multi-process environment for DeepSpeed to work. This means you have to use the `deepspeed` launcher which can't be emulated as shown here.

```py
# DeepSpeed requires a distributed environment even when only one process is used.


key: _node_content
string_value:
{"id_": "ed8442fd-4d08-45c8-be48-714b9579b9d4", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "bf1a66e0-7f6d-4a8c-980c-ce13523617ee", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "ec786e6d2bd4b33aa9e68156c47dc0b09d0cef3bf7044a4915eba228a9f9204b", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "fac84311-ae40-47ac-a583-c4acf1ef03ac", "node_type": "1", "metadata": {}, "hash": "ed5fc67b85481cf8284f99a78f496c7902f6281d388dc92ee78a6a4d6187b8db", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 34139, "end_char_idx": 36192, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
An example SLURM script may look like:

```bash
#SBATCH --job-name=test-nodes        # name
#SBATCH --nodes=2                    # nodes
#SBATCH --ntasks-per-node=1          # crucial - only 1 task per dist per node!
#SBATCH --cpus-per-task=10           # number of cores per tasks
#SBATCH --gres=gpu:8                 # number of gpus
#SBATCH --time 20:00:00              # maximum execution time (HH:MM:SS)
#SBATCH --output=%x-%j.out           # output file name

export GPUS_PER_NODE=8
export MASTER_ADDR=$(scontrol show hostnames $SLURM_JOB_NODELIST | head -n 1)
export MASTER_PORT=9901

srun --jobid $SLURM_JOBID bash -c 'python -m torch.distributed.run \
 --nproc_per_node $GPUS_PER_NODE --nnodes $SLURM_NNODES --node_rank $SLURM_PROCID \
 --master_addr $MASTER_ADDR --master_port $MASTER_PORT \
your_program.py <normal cl args> --deepspeed ds_config.json'
```

Then you can schedule your multi-node deployment with the following command which launches training simultaneously on all nodes.

```bash
sbatch launch.slurm
```

### Notebook

The `deepspeed` launcher doesn't support deployment from a notebook so you'll need to emulate the distributed environment. However, this only works for 1 GPU. If you want to use more than 1 GPU, you must use a multi-process environment for DeepSpeed to work. This means you have to use the `deepspeed` launcher which can't be emulated as shown here.

```py
# DeepSpeed requires a distributed environment even when only one process is used.
# This emulates a launcher in the notebook
import os

os.environ["MASTER_ADDR"] = "localhost"
os.environ["MASTER_PORT"] = "9994"  # modify if RuntimeError: Address already in use
os.environ["RANK"] = "0"
os.environ["LOCAL_RANK"] = "0"
os.environ["WORLD_SIZE"] = "1"

# Now proceed as normal, plus pass the DeepSpeed config file
training_args = TrainingArguments(..., deepspeed="ds_config_zero3.json")
trainer = Trainer(...)
trainer.train()
```

If you want to create the config file on the fly in the notebook in the current directory, you could have a dedicated cell.


key: _node_content
string_value:
{"id_": "fac84311-ae40-47ac-a583-c4acf1ef03ac", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "ed8442fd-4d08-45c8-be48-714b9579b9d4", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "db02e2e85bbb771bbfbaad531b9126488c33f6c6d45a6f41037ddd9f341a65a5", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "63fff344-5914-4f92-b9a0-0ed9f7617a1b", "node_type": "1", "metadata": {}, "hash": "1fc13e4f41510f9748c5999738a99581e93c4d8d01a6fe635d09fee4417bdbae", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 35137, "end_char_idx": 37836, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
```bash
sbatch launch.slurm
```

### Notebook

The `deepspeed` launcher doesn't support deployment from a notebook so you'll need to emulate the distributed environment. However, this only works for 1 GPU. If you want to use more than 1 GPU, you must use a multi-process environment for DeepSpeed to work. This means you have to use the `deepspeed` launcher which can't be emulated as shown here.

```py
# DeepSpeed requires a distributed environment even when only one process is used.
# This emulates a launcher in the notebook
import os

os.environ["MASTER_ADDR"] = "localhost"
os.environ["MASTER_PORT"] = "9994"  # modify if RuntimeError: Address already in use
os.environ["RANK"] = "0"
os.environ["LOCAL_RANK"] = "0"
os.environ["WORLD_SIZE"] = "1"

# Now proceed as normal, plus pass the DeepSpeed config file
training_args = TrainingArguments(..., deepspeed="ds_config_zero3.json")
trainer = Trainer(...)
trainer.train()
```

If you want to create the config file on the fly in the notebook in the current directory, you could have a dedicated cell.

```py
%%bash
cat <<'EOT' > ds_config_zero3.json
{
    "fp16": {
        "enabled": "auto",
        "loss_scale": 0,
        "loss_scale_window": 1000,
        "initial_scale_power": 16,
        "hysteresis": 2,
        "min_loss_scale": 1
    },

    "optimizer": {
        "type": "AdamW",
        "params": {
            "lr": "auto",
            "betas": "auto",
            "eps": "auto",
            "weight_decay": "auto"
        }
    },

    "scheduler": {
        "type": "WarmupLR",
        "params": {
            "warmup_min_lr": "auto",
            "warmup_max_lr": "auto",
            "warmup_num_steps": "auto"
        }
    },

    "zero_optimization": {
        "stage": 3,
        "offload_optimizer": {
            "device": "cpu",
            "pin_memory": true
        },
        "offload_param": {
            "device": "cpu",
            "pin_memory": true
        },
        "overlap_comm": true,
        "contiguous_gradients": true,
        "sub_group_size": 1e9,
        "reduce_bucket_size": "auto",
        "stage3_prefetch_bucket_size": "auto",
        "stage3_param_persistence_threshold": "auto",
        "stage3_max_live_parameters": 1e9,
        "stage3_max_reuse_distance": 1e9,
        "stage3_gather_16bit_weights_on_model_save": true
    },

    "gradient_accumulation_steps": "auto",
    "gradient_clipping": "auto",
    "steps_per_print": 2000,
    "train_batch_size": "auto",
    "train_micro_batch_size_per_gpu": "auto",
    "wall_clock_breakdown": false
}
EOT
```

If the training script is in a file and not in a notebook cell, you can launch `deepspeed` normally from the shell in a notebook cell.


key: _node_content
string_value:
{"id_": "63fff344-5914-4f92-b9a0-0ed9f7617a1b", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "fac84311-ae40-47ac-a583-c4acf1ef03ac", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "db478fb565afdac90847ce2a6e155c6f36b0ede83a0376646e78194de49314a2", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "9d098ecc-9800-4ea9-a7b4-49ae6820b283", "node_type": "1", "metadata": {}, "hash": "20888e50e29d7df9606751a329a30ed75fd4e57255c9e46abc727aa5d583ac93", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 37837, "end_char_idx": 40898, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
For example, to launch `run_translation.py`:

```py
!git clone https://github.com/huggingface/transformers
!cd transformers; deepspeed examples/pytorch/translation/run_translation.py ...
```

You could also use `%%bash` magic and write multi-line code to run the shell program, but you won't be able to view the logs until training is complete. With `%%bash` magic, you don't need to emulate a distributed environment.

```py
%%bash

git clone https://github.com/huggingface/transformers
cd transformers
deepspeed examples/pytorch/translation/run_translation.py ...
```

## Save model weights

DeepSpeed stores the main full precision fp32 weights in custom checkpoint optimizer files (the glob pattern looks like `global_step*/*optim_states.pt`) and are saved under the normal checkpoint.

<hfoptions id="save">
<hfoption id="fp16">

A model trained with ZeRO-2 saves the pytorch_model.bin weights in fp16. To save the model weights in fp16 for a model trained with ZeRO-3, you need to set `"stage3_gather_16bit_weights_on_model_save": true` because the model weights are partitioned across multiple GPUs. Otherwise, the [`Trainer`] won't save the weights in fp16 and it won't create a pytorch_model.bin file. This is because DeepSpeed's state_dict contains a placeholder instead of the real weights and you won't be able to load them.

```yaml
{
    "zero_optimization": {
        "stage3_gather_16bit_weights_on_model_save": true
    }
}
```

</hfoption>
<hfoption id="fp32">

The full precision weights shouldn't be saved during training because it can require a lot of memory. It is usually best to save the fp32 weights offline after training is complete. But if you have a lot of free CPU memory, it is possible to save the fp32 weights during training. This section covers both online and offline approaches.

### Online

You must have saved at least one checkpoint to load the latest checkpoint as shown in the following:

```py
from transformers.trainer_utils import get_last_checkpoint
from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint

checkpoint_dir = get_last_checkpoint(trainer.args.output_dir)
fp32_model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
```

If you've enabled the `--load_best_model_at_end` parameter to track the best checkpoint in [`TrainingArguments`], you can finish training first and save the final model explicitly. Then you can reload it as shown below:

```py
from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint

checkpoint_dir = os.path.join(trainer.args.output_dir, "checkpoint-final")
trainer.deepspeed.save_checkpoint(checkpoint_dir)
fp32_model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
```

<Tip>

Once `load_state_dict_from_zero_checkpoint` is run, the model is no longer usable in DeepSpeed in the context of the same application. You'll need to initialize the DeepSpeed engine again since `model.load_state_dict(state_dict)` removes all the DeepSpeed magic from it. Only use this at the very end of training.


key: _node_content
string_value:
{"id_": "9d098ecc-9800-4ea9-a7b4-49ae6820b283", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "63fff344-5914-4f92-b9a0-0ed9f7617a1b", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "b6c028b0213e0cceb2bed0b08d06490069d9d8f40906656c95af18a608362f78", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "5e01cd34-2939-4f2a-8bdd-8ef6256f47ca", "node_type": "1", "metadata": {}, "hash": "51c3cdc4c60328e39e9f3d56d940885bb0aba06d345681fb5bd03b6515cc8961", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 39175, "end_char_idx": 41430, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
```yaml
{
    "zero_optimization": {
        "stage3_gather_16bit_weights_on_model_save": true
    }
}
```

</hfoption>
<hfoption id="fp32">

The full precision weights shouldn't be saved during training because it can require a lot of memory. It is usually best to save the fp32 weights offline after training is complete. But if you have a lot of free CPU memory, it is possible to save the fp32 weights during training. This section covers both online and offline approaches.

### Online

You must have saved at least one checkpoint to load the latest checkpoint as shown in the following:

```py
from transformers.trainer_utils import get_last_checkpoint
from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint

checkpoint_dir = get_last_checkpoint(trainer.args.output_dir)
fp32_model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
```

If you've enabled the `--load_best_model_at_end` parameter to track the best checkpoint in [`TrainingArguments`], you can finish training first and save the final model explicitly. Then you can reload it as shown below:

```py
from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint

checkpoint_dir = os.path.join(trainer.args.output_dir, "checkpoint-final")
trainer.deepspeed.save_checkpoint(checkpoint_dir)
fp32_model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
```

<Tip>

Once `load_state_dict_from_zero_checkpoint` is run, the model is no longer usable in DeepSpeed in the context of the same application. You'll need to initialize the DeepSpeed engine again since `model.load_state_dict(state_dict)` removes all the DeepSpeed magic from it. Only use this at the very end of training.

</Tip>

You can also extract and load the state_dict of the fp32 weights:

```py
from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint

state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir)  # already on cpu
model = model.cpu()
model.load_state_dict(state_dict)
```

### Offline

DeepSpeed provides a zero_to_fp32.py script at the top-level of the checkpoint folder for extracting weights at any point. This is a standalone script and you don't need a configuration file or [`Trainer`].


key: _node_content
string_value:
{"id_": "5e01cd34-2939-4f2a-8bdd-8ef6256f47ca", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "9d098ecc-9800-4ea9-a7b4-49ae6820b283", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "133f7875b3818a0ed84f617e9e96072cf6038e3229eb090eda2a5d03f8cd8347", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "be0ad5b6-727f-4c80-8038-2d6d57605972", "node_type": "1", "metadata": {}, "hash": "7f929c4725a79004d526026ec489672acf83bdc611dc090fbe4379bb3b0d1971", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 39598, "end_char_idx": 42455, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
This section covers both online and offline approaches.

### Online

You must have saved at least one checkpoint to load the latest checkpoint as shown in the following:

```py
from transformers.trainer_utils import get_last_checkpoint
from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint

checkpoint_dir = get_last_checkpoint(trainer.args.output_dir)
fp32_model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
```

If you've enabled the `--load_best_model_at_end` parameter to track the best checkpoint in [`TrainingArguments`], you can finish training first and save the final model explicitly. Then you can reload it as shown below:

```py
from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint

checkpoint_dir = os.path.join(trainer.args.output_dir, "checkpoint-final")
trainer.deepspeed.save_checkpoint(checkpoint_dir)
fp32_model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
```

<Tip>

Once `load_state_dict_from_zero_checkpoint` is run, the model is no longer usable in DeepSpeed in the context of the same application. You'll need to initialize the DeepSpeed engine again since `model.load_state_dict(state_dict)` removes all the DeepSpeed magic from it. Only use this at the very end of training.

</Tip>

You can also extract and load the state_dict of the fp32 weights:

```py
from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint

state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir)  # already on cpu
model = model.cpu()
model.load_state_dict(state_dict)
```

### Offline

DeepSpeed provides a zero_to_fp32.py script at the top-level of the checkpoint folder for extracting weights at any point. This is a standalone script and you don't need a configuration file or [`Trainer`].

For example, if your checkpoint folder looked like this:

```bash
$ ls -l output_dir/checkpoint-1/
-rw-rw-r-- 1 stas stas 1.4K Mar 27 20:42 config.json
drwxrwxr-x 2 stas stas 4.0K Mar 25 19:52 global_step1/
-rw-rw-r-- 1 stas stas   12 Mar 27 13:16 latest
-rw-rw-r-- 1 stas stas 827K Mar 27 20:42 optimizer.pt
-rw-rw-r-- 1 stas stas 231M Mar 27 20:42 pytorch_model.bin
-rw-rw-r-- 1 stas stas  623 Mar 27 20:42 scheduler.pt
-rw-rw-r-- 1 stas stas 1.8K Mar 27 20:42 special_tokens_map.json
-rw-rw-r-- 1 stas stas 774K Mar 27 20:42 spiece.model
-rw-rw-r-- 1 stas stas 1.9K Mar 27 20:42 tokenizer_config.json
-rw-rw-r-- 1 stas stas  339 Mar 27 20:42 trainer_state.json
-rw-rw-r-- 1 stas stas 2.3K Mar 27 20:42 training_args.bin
-rwxrw-r-- 1 stas stas 5.5K Mar 27 13:16 zero_to_fp32.py*
```

To reconstruct the fp32 weights from the DeepSpeed checkpoint (ZeRO-2 or ZeRO-3) subfolder `global_step1`, run the following command to create and consolidate the full fp32 weights from multiple GPUs into a single pytorch_model.bin file.


key: _node_content
string_value:
{"id_": "be0ad5b6-727f-4c80-8038-2d6d57605972", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "5e01cd34-2939-4f2a-8bdd-8ef6256f47ca", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "7808c651345a3767cf0cd4603bda6bd726d832ff032be1c40aae795cacdfaab6", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "f9b22969-0056-44fe-bf59-e8c3cc9af4ca", "node_type": "1", "metadata": {}, "hash": "3cf560e95490b20f80fddaaba9ac8641a7b08ab155af421cbdacb264135fc3eb", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 42456, "end_char_idx": 45633, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
The script automatically discovers the subfolder containing the checkpoint.

```py
python zero_to_fp32.py . pytorch_model.bin
```

<Tip>

Run `python zero_to_fp32.py -h` for more usage details. The script requires 2x the general RAM of the final fp32 weights.

</Tip>

</hfoption>
</hfoptions>

## ZeRO Inference

[ZeRO Inference](https://www.deepspeed.ai/2022/09/09/zero-inference.html) places the model weights in CPU or NVMe memory to avoid burdening the GPU which makes it possible to run inference with huge models on a GPU. Inference doesn't require any large additional amounts of memory for the optimizer states and gradients so you can fit much larger batches and/or sequence lengths on the same hardware.

ZeRO Inference shares the same configuration file as [ZeRO-3](#zero-configuration), and ZeRO-2 and ZeRO-1 configs won't work because they don't provide any benefits for inference.

To run ZeRO Inference, pass your usual training arguments to the [`TrainingArguments`] class and add the `--do_eval` argument.

```bash
deepspeed --num_gpus=2 your_program.py <normal cl args> --do_eval --deepspeed ds_config.json
```

## Non-Trainer DeepSpeed integration

DeepSpeed also works with Transformers without the [`Trainer`] class. This is handled by the [`HfDeepSpeedConfig`] which only takes care of gathering ZeRO-3 parameters and splitting a model across multiple GPUs when you call [`~PreTrainedModel.from_pretrained`].

<Tip>

If you want everything automatically taken care of for you, try using DeepSpeed with the [`Trainer`]! You'll need to follow the [DeepSpeed documentation](https://www.deepspeed.ai/), and manually configure the parameter values in the config file (you can't use the `"auto"` value).

</Tip>

To efficiently deploy ZeRO-3, you must instantiate the [`HfDeepSpeedConfig`] object before the model and keep that object alive:

<hfoptions id="models">
<hfoption id="pretrained model">

```py
from transformers.integrations import HfDeepSpeedConfig
from transformers import AutoModel
import deepspeed

ds_config = {...}  # deepspeed config object or path to the file
# must run before instantiating the model to detect zero 3
dschf = HfDeepSpeedConfig(ds_config)  # keep this object alive
model = AutoModel.from_pretrained("openai-community/gpt2")
engine = deepspeed.initialize(model=model, config_params=ds_config, ...)
```

</hfoption>
<hfoption id="non-pretrained model">

[`HfDeepSpeedConfig`] is not required for ZeRO-1 or ZeRO-2.

```py
from transformers.integrations import HfDeepSpeedConfig
from transformers import AutoModel, AutoConfig
import deepspeed

ds_config = {...}  # deepspeed config object or path to the file
# must run before instantiating the model to detect zero 3
dschf = HfDeepSpeedConfig(ds_config)  # keep this object alive
config = AutoConfig.from_pretrained("openai-community/gpt2")
model = AutoModel.from_config(config)
engine = deepspeed.initialize(model=model, config_params=ds_config, ...)
```

</hfoption>
</hfoptions>

### Non-Trainer ZeRO Inference

To run ZeRO Inference without the [`Trainer`] in cases where you can’t fit a model onto a single GPU, try using additional GPUs or/and offloading to CPU memory.


key: _node_content
string_value:
{"id_": "f9b22969-0056-44fe-bf59-e8c3cc9af4ca", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "be0ad5b6-727f-4c80-8038-2d6d57605972", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "128c82e8405b2a01668997f40bbebd457c5972aa8ef4c4d73dbf4300eb0c620d", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "825bdde4-db58-43eb-b4d7-7289fa3ccd65", "node_type": "1", "metadata": {}, "hash": "bc502238b44027b2e5282dd3a487ae1c8d8123140144a8359ae32f17957e2782", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 44178, "end_char_idx": 47184, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
</Tip>

To efficiently deploy ZeRO-3, you must instantiate the [`HfDeepSpeedConfig`] object before the model and keep that object alive:

<hfoptions id="models">
<hfoption id="pretrained model">

```py
from transformers.integrations import HfDeepSpeedConfig
from transformers import AutoModel
import deepspeed

ds_config = {...}  # deepspeed config object or path to the file
# must run before instantiating the model to detect zero 3
dschf = HfDeepSpeedConfig(ds_config)  # keep this object alive
model = AutoModel.from_pretrained("openai-community/gpt2")
engine = deepspeed.initialize(model=model, config_params=ds_config, ...)
```

</hfoption>
<hfoption id="non-pretrained model">

[`HfDeepSpeedConfig`] is not required for ZeRO-1 or ZeRO-2.

```py
from transformers.integrations import HfDeepSpeedConfig
from transformers import AutoModel, AutoConfig
import deepspeed

ds_config = {...}  # deepspeed config object or path to the file
# must run before instantiating the model to detect zero 3
dschf = HfDeepSpeedConfig(ds_config)  # keep this object alive
config = AutoConfig.from_pretrained("openai-community/gpt2")
model = AutoModel.from_config(config)
engine = deepspeed.initialize(model=model, config_params=ds_config, ...)
```

</hfoption>
</hfoptions>

### Non-Trainer ZeRO Inference

To run ZeRO Inference without the [`Trainer`] in cases where you can’t fit a model onto a single GPU, try using additional GPUs or/and offloading to CPU memory. The important nuance to understand here is that the way ZeRO is designed, you can process different inputs on different GPUs in parallel.

Make sure to:

* disable CPU offload if you have enough GPU memory (since it slows things down).
* enable bf16 if you have an Ampere or newer GPU to make things faster. If you don’t have one of these GPUs, you may enable fp16 as long as you don’t use a model pretrained in bf16 (T5 models) because it may lead to an overflow error.

Take a look at the following script to get a better idea of how to run ZeRO Inference without the [`Trainer`] on a model that won't fit on a single GPU.

```py
#!/usr/bin/env python

# This script demonstrates how to use Deepspeed ZeRO in an inference mode when one can't fit a model
# into a single GPU
#
# 1. Use 1 GPU with CPU offload
# 2. Or use multiple GPUs instead
#
# First you need to install deepspeed: pip install deepspeed
#
# Here we use a 3B "bigscience/T0_3B" model which needs about 15GB GPU RAM - so 1 largish or 2
# small GPUs can handle it. or 1 small GPU and a lot of CPU memory.
#
# To use a larger model like "bigscience/T0" which needs about 50GB, unless you have an 80GB GPU -
# you will need 2-4 gpus. And then you can adapt the script to handle more gpus if you want to
# process multiple inputs at once.
#
# The provided deepspeed config also activates CPU memory offloading, so chances are that if you
# have a lot of available CPU memory and you don't mind a slowdown you should be able to load a
# model that doesn't normally fit into a single GPU.


key: _node_content
string_value:
{"id_": "825bdde4-db58-43eb-b4d7-7289fa3ccd65", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "f9b22969-0056-44fe-bf59-e8c3cc9af4ca", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "4ffd85ad8f839ff906ce900ba683f9d3a8a194534074f661ec678bbd1203554f", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "31c9b82c-cb47-425b-ba02-6d15e03a29a1", "node_type": "1", "metadata": {}, "hash": "7415ba0d0d9abd3b32a52e28afbde2a793d58b977230237603673bf09f5e7749", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 45773, "end_char_idx": 48464, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
Make sure to:

* disable CPU offload if you have enough GPU memory (since it slows things down).
* enable bf16 if you have an Ampere or newer GPU to make things faster. If you don’t have one of these GPUs, you may enable fp16 as long as you don’t use a model pretrained in bf16 (T5 models) because it may lead to an overflow error.

Take a look at the following script to get a better idea of how to run ZeRO Inference without the [`Trainer`] on a model that won't fit on a single GPU.

```py
#!/usr/bin/env python

# This script demonstrates how to use Deepspeed ZeRO in an inference mode when one can't fit a model
# into a single GPU
#
# 1. Use 1 GPU with CPU offload
# 2. Or use multiple GPUs instead
#
# First you need to install deepspeed: pip install deepspeed
#
# Here we use a 3B "bigscience/T0_3B" model which needs about 15GB GPU RAM - so 1 largish or 2
# small GPUs can handle it. or 1 small GPU and a lot of CPU memory.
#
# To use a larger model like "bigscience/T0" which needs about 50GB, unless you have an 80GB GPU -
# you will need 2-4 gpus. And then you can adapt the script to handle more gpus if you want to
# process multiple inputs at once.
#
# The provided deepspeed config also activates CPU memory offloading, so chances are that if you
# have a lot of available CPU memory and you don't mind a slowdown you should be able to load a
# model that doesn't normally fit into a single GPU. If you have enough GPU memory the program will
# run faster if you don't want offload to CPU - so disable that section then.
#
# To deploy on 1 gpu:
#
# deepspeed --num_gpus 1 t0.py
# or:
# python -m torch.distributed.run --nproc_per_node=1 t0.py
#
# To deploy on 2 gpus:
#
# deepspeed --num_gpus 2 t0.py
# or:
# python -m torch.distributed.run --nproc_per_node=2 t0.py

from transformers import AutoTokenizer, AutoConfig, AutoModelForSeq2SeqLM
from transformers.integrations import HfDeepSpeedConfig
import deepspeed
import os
import torch

os.environ["TOKENIZERS_PARALLELISM"] = "false"  # To avoid warnings about parallelism in tokenizers

# distributed setup
local_rank = int(os.getenv("LOCAL_RANK", "0"))
world_size = int(os.getenv("WORLD_SIZE", "1"))
torch.cuda.set_device(local_rank)
deepspeed.init_distributed()

model_name = "bigscience/T0_3B"

config = AutoConfig.from_pretrained(model_name)
model_hidden_size = config.d_model

# batch size has to be divisible by world_size, but can be bigger than world_size
train_batch_size = 1 * world_size

# ds_config notes
#
# - enable bf16 if you use Ampere or higher GPU - this will run in mixed precision and will be
# faster.
#
# - for older GPUs you can enable fp16, but it'll only work for non-bf16 pretrained models - e.g.


key: _node_content
string_value:
{"id_": "31c9b82c-cb47-425b-ba02-6d15e03a29a1", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "825bdde4-db58-43eb-b4d7-7289fa3ccd65", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "746dbaaf16bf3fe64122afc0dfa1affe70c88f5aa06eeb782cdb30b5d1798cc8", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "7ccb325d-9905-40d3-958c-aaf7caa6b2fa", "node_type": "1", "metadata": {}, "hash": "d3bf100c4b6cdc92113609c0209b02f97789cf74ea8d4f6e95dd1ad6fcc492fd", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 47185, "end_char_idx": 49918, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
If you have enough GPU memory the program will
# run faster if you don't want offload to CPU - so disable that section then.
#
# To deploy on 1 gpu:
#
# deepspeed --num_gpus 1 t0.py
# or:
# python -m torch.distributed.run --nproc_per_node=1 t0.py
#
# To deploy on 2 gpus:
#
# deepspeed --num_gpus 2 t0.py
# or:
# python -m torch.distributed.run --nproc_per_node=2 t0.py

from transformers import AutoTokenizer, AutoConfig, AutoModelForSeq2SeqLM
from transformers.integrations import HfDeepSpeedConfig
import deepspeed
import os
import torch

os.environ["TOKENIZERS_PARALLELISM"] = "false"  # To avoid warnings about parallelism in tokenizers

# distributed setup
local_rank = int(os.getenv("LOCAL_RANK", "0"))
world_size = int(os.getenv("WORLD_SIZE", "1"))
torch.cuda.set_device(local_rank)
deepspeed.init_distributed()

model_name = "bigscience/T0_3B"

config = AutoConfig.from_pretrained(model_name)
model_hidden_size = config.d_model

# batch size has to be divisible by world_size, but can be bigger than world_size
train_batch_size = 1 * world_size

# ds_config notes
#
# - enable bf16 if you use Ampere or higher GPU - this will run in mixed precision and will be
# faster.
#
# - for older GPUs you can enable fp16, but it'll only work for non-bf16 pretrained models - e.g.
# all official t5 models are bf16-pretrained
#
# - set offload_param.device to "none" or completely remove the `offload_param` section if you don't
# - want CPU offload
#
# - if using `offload_param` you can manually finetune stage3_param_persistence_threshold to control
# - which params should remain on gpus - the larger the value the smaller the offload size
#
# For in-depth info on Deepspeed config see
# https://huggingface.co/docs/transformers/main/main_classes/deepspeed

# keeping the same format as json for consistency, except it uses lower case for true/false
# fmt: off
ds_config = {
    "fp16": {
        "enabled": False
    },
    "bf16": {
        "enabled": False
    },
    "zero_optimization": {
        "stage": 3,
        "offload_param": {
            "device": "cpu",
            "pin_memory": True
        },
        "overlap_comm": True,
        "contiguous_gradients": True,
        "reduce_bucket_size": model_hidden_size * model_hidden_size,
        "stage3_prefetch_bucket_size": 0.9 * model_hidden_size * model_hidden_size,
        "stage3_param_persistence_threshold": 10 * model_hidden_size
    },
    "steps_per_print": 2000,
    "train_batch_size": train_batch_size,
    "train_micro_batch_size_per_gpu": 1,
    "wall_clock_breakdown": False
}
# fmt: on

# next line instructs transformers to partition the model directly over multiple gpus using
# deepspeed.zero.Init when model's `from_pretrained` method is called.


key: _node_content
string_value:
{"id_": "7ccb325d-9905-40d3-958c-aaf7caa6b2fa", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "31c9b82c-cb47-425b-ba02-6d15e03a29a1", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "71a659bf8543324db0e2e363cfca30e78cc860125dfdba776beaebabad98383b", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "453457f3-8031-4b6b-aeba-4ad6ecf8b3c3", "node_type": "1", "metadata": {}, "hash": "f992ddf2a684638556da25a46c2ccf32caa85cf42436590352c56838ab0cb6e0", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 48365, "end_char_idx": 51041, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
#
# - for older GPUs you can enable fp16, but it'll only work for non-bf16 pretrained models - e.g.
# all official t5 models are bf16-pretrained
#
# - set offload_param.device to "none" or completely remove the `offload_param` section if you don't
# - want CPU offload
#
# - if using `offload_param` you can manually finetune stage3_param_persistence_threshold to control
# - which params should remain on gpus - the larger the value the smaller the offload size
#
# For in-depth info on Deepspeed config see
# https://huggingface.co/docs/transformers/main/main_classes/deepspeed

# keeping the same format as json for consistency, except it uses lower case for true/false
# fmt: off
ds_config = {
    "fp16": {
        "enabled": False
    },
    "bf16": {
        "enabled": False
    },
    "zero_optimization": {
        "stage": 3,
        "offload_param": {
            "device": "cpu",
            "pin_memory": True
        },
        "overlap_comm": True,
        "contiguous_gradients": True,
        "reduce_bucket_size": model_hidden_size * model_hidden_size,
        "stage3_prefetch_bucket_size": 0.9 * model_hidden_size * model_hidden_size,
        "stage3_param_persistence_threshold": 10 * model_hidden_size
    },
    "steps_per_print": 2000,
    "train_batch_size": train_batch_size,
    "train_micro_batch_size_per_gpu": 1,
    "wall_clock_breakdown": False
}
# fmt: on

# next line instructs transformers to partition the model directly over multiple gpus using
# deepspeed.zero.Init when model's `from_pretrained` method is called.
#
# **it has to be run before loading the model AutoModelForSeq2SeqLM.from_pretrained(model_name)**
#
# otherwise the model will first be loaded normally and only partitioned at forward time which is
# less efficient and when there is little CPU RAM may fail
dschf = HfDeepSpeedConfig(ds_config)  # keep this object alive

# now a model can be loaded.
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

# initialise Deepspeed ZeRO and store only the engine object
ds_engine = deepspeed.initialize(model=model, config_params=ds_config)[0]
ds_engine.module.eval()  # inference

# Deepspeed ZeRO can process unrelated inputs on each GPU. So for 2 gpus you process 2 inputs at once.
# If you use more GPUs adjust for more.
# And of course if you have just one input to process you then need to pass the same string to both gpus
# If you use only one GPU, then you will have only rank 0.
rank = torch.distributed.get_rank()
if rank == 0:
    text_in = "Is this review positive or negative? Review: this is the best cast iron skillet you will ever buy"
elif rank == 1:
    text_in = "Is this review positive or negative?


key: _node_content
string_value:
{"id_": "453457f3-8031-4b6b-aeba-4ad6ecf8b3c3", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "7ccb325d-9905-40d3-958c-aaf7caa6b2fa", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "b7c1a89ebc04e39594f0a10e2492914db55cb7a60ce6ecc4aac6a7ec3b81bbe3", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "9ee03198-8c08-48e5-a15d-9dc3d0a12f9f", "node_type": "1", "metadata": {}, "hash": "6d6b78dfbb1294847f21e9191f445c51d71268caba472c165cafab67fc07bdc8", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 49919, "end_char_idx": 52815, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
#
# **it has to be run before loading the model AutoModelForSeq2SeqLM.from_pretrained(model_name)**
#
# otherwise the model will first be loaded normally and only partitioned at forward time which is
# less efficient and when there is little CPU RAM may fail
dschf = HfDeepSpeedConfig(ds_config)  # keep this object alive

# now a model can be loaded.
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

# initialise Deepspeed ZeRO and store only the engine object
ds_engine = deepspeed.initialize(model=model, config_params=ds_config)[0]
ds_engine.module.eval()  # inference

# Deepspeed ZeRO can process unrelated inputs on each GPU. So for 2 gpus you process 2 inputs at once.
# If you use more GPUs adjust for more.
# And of course if you have just one input to process you then need to pass the same string to both gpus
# If you use only one GPU, then you will have only rank 0.
rank = torch.distributed.get_rank()
if rank == 0:
    text_in = "Is this review positive or negative? Review: this is the best cast iron skillet you will ever buy"
elif rank == 1:
    text_in = "Is this review positive or negative? Review: this is the worst restaurant ever"

tokenizer = AutoTokenizer.from_pretrained(model_name)
inputs = tokenizer.encode(text_in, return_tensors="pt").to(device=local_rank)
with torch.no_grad():
    outputs = ds_engine.module.generate(inputs, synced_gpus=True)
text_out = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(f"rank{rank}:\n   in={text_in}\n  out={text_out}")
```

Save the script as t0.py and launch it:

```bash
$ deepspeed --num_gpus 2 t0.py
rank0:
   in=Is this review positive or negative? Review: this is the best cast iron skillet you will ever buy
  out=Positive
rank1:
   in=Is this review positive or negative? Review: this is the worst restaurant ever
  out=negative
```

This is a very basic example and you'll want to adapt it to your use case.

### Generate

Using multiple GPUs with ZeRO-3 for generation requires synchronizing the GPUs by setting `synced_gpus=True` in the [`~GenerationMixin.generate`] method. Otherwise, if one GPU is finished generating before another one, the whole system hangs because the remaining GPUs haven't received the weight shard from the GPU that finished first.

For Transformers>=4.28, if `synced_gpus` is automatically set to `True` if multiple GPUs are detected during generation.

## Troubleshoot

When you encounter an issue, you should consider whether DeepSpeed is the cause of the problem because often it isn't (unless it's super obviously and you can see DeepSpeed modules in the exception)! The first step should be to retry your setup without DeepSpeed, and if the problem persists, then you can report the issue. If the issue is a core DeepSpeed problem and unrelated to the Transformers integration, open an Issue on the [DeepSpeed repository](https://github.com/microsoft/DeepSpeed).


key: _node_content
string_value:
{"id_": "9ee03198-8c08-48e5-a15d-9dc3d0a12f9f", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "453457f3-8031-4b6b-aeba-4ad6ecf8b3c3", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "f1111519a27f62158d2cbffb42df235e107f9d9d0f16b1a09c186f791b750482", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "b521c736-88f0-4c0a-b5a8-51298ba5acc9", "node_type": "1", "metadata": {}, "hash": "ed1c51766d2bd15f242f2e480c2ac869014719c80c6109070d5d6f4646b34ebe", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 51564, "end_char_idx": 54620, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
Review: this is the best cast iron skillet you will ever buy
  out=Positive
rank1:
   in=Is this review positive or negative? Review: this is the worst restaurant ever
  out=negative
```

This is a very basic example and you'll want to adapt it to your use case.

### Generate

Using multiple GPUs with ZeRO-3 for generation requires synchronizing the GPUs by setting `synced_gpus=True` in the [`~GenerationMixin.generate`] method. Otherwise, if one GPU is finished generating before another one, the whole system hangs because the remaining GPUs haven't received the weight shard from the GPU that finished first.

For Transformers>=4.28, if `synced_gpus` is automatically set to `True` if multiple GPUs are detected during generation.

## Troubleshoot

When you encounter an issue, you should consider whether DeepSpeed is the cause of the problem because often it isn't (unless it's super obviously and you can see DeepSpeed modules in the exception)! The first step should be to retry your setup without DeepSpeed, and if the problem persists, then you can report the issue. If the issue is a core DeepSpeed problem and unrelated to the Transformers integration, open an Issue on the [DeepSpeed repository](https://github.com/microsoft/DeepSpeed).

For issues related to the Transformers integration, please provide the following information:

* the full DeepSpeed config file

* the command line arguments of the [`Trainer`], or [`TrainingArguments`] arguments if you're scripting the [`Trainer`] setup yourself (don't dump the [`TrainingArguments`] which has dozens of irrelevant entries)

* the outputs of:

```bash
python -c 'import torch; print(f"torch: {torch.__version__}")'
python -c 'import transformers; print(f"transformers: {transformers.__version__}")'
python -c 'import deepspeed; print(f"deepspeed: {deepspeed.__version__}")'
```

* a link to a Google Colab notebook to reproduce the issue

* if impossible, a standard and non-custom dataset we can use and also try to use an existing example to reproduce the issue with

The following sections provide a guide for resolving two of the most common issues.

### DeepSpeed process killed at startup

When the DeepSpeed process is killed during launch without a traceback, that usually means the program tried to allocate more CPU memory than your system has or your process tried to allocate more CPU memory than allowed leading the OS kernel to terminate the process. In this case, check whether your configuration file has either `offload_optimizer`, `offload_param` or both configured to offload to the CPU. 

If you have NVMe and ZeRO-3 setup, experiment with offloading to the NVMe ([estimate](https://deepspeed.readthedocs.io/en/latest/memory.html) the memory requirements for your model).

### NaN loss

NaN loss often occurs when a model is pretrained in bf16 and then you try to use it with fp16 (especially relevant for TPU trained models). To resolve this, use fp32 or bf16 if your hardware supports it (TPU, Ampere GPUs or newer).

The other issue may be related to using fp16.


key: _node_content
string_value:
{"id_": "b521c736-88f0-4c0a-b5a8-51298ba5acc9", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "9ee03198-8c08-48e5-a15d-9dc3d0a12f9f", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "2c6e9f7e4a23298ddca1ebd156e0a0adbbb417f435f6f2b2736c8ec5bd1cdd57", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "4a5a73f4-35d8-42a2-9667-6b85d5ffe303", "node_type": "1", "metadata": {}, "hash": "155d9b4dc92b350674f861a8bc9dbf32eb14ce6e8be60d042b6ef57112deaee2", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 53690, "end_char_idx": 56633, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
### DeepSpeed process killed at startup

When the DeepSpeed process is killed during launch without a traceback, that usually means the program tried to allocate more CPU memory than your system has or your process tried to allocate more CPU memory than allowed leading the OS kernel to terminate the process. In this case, check whether your configuration file has either `offload_optimizer`, `offload_param` or both configured to offload to the CPU. 

If you have NVMe and ZeRO-3 setup, experiment with offloading to the NVMe ([estimate](https://deepspeed.readthedocs.io/en/latest/memory.html) the memory requirements for your model).

### NaN loss

NaN loss often occurs when a model is pretrained in bf16 and then you try to use it with fp16 (especially relevant for TPU trained models). To resolve this, use fp32 or bf16 if your hardware supports it (TPU, Ampere GPUs or newer).

The other issue may be related to using fp16. For example, if this is your fp16 configuration:

```yaml
{
    "fp16": {
        "enabled": "auto",
        "loss_scale": 0,
        "loss_scale_window": 1000,
        "initial_scale_power": 16,
        "hysteresis": 2,
        "min_loss_scale": 1
    }
}
```

You might see the following `OVERFLOW!` messages in the logs:

```bash
0%|                                                                                                                             | 0/189 [00:00<?, ?it/s]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 262144, reducing to 262144
  1%|▌                                                                                                                    | 1/189 [00:00<01:26,  2.17it/s]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 262144, reducing to 131072.0
  1%|█▏
 [...]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 1, reducing to 1
 14%|████████████████▌                                                                                                   | 27/189 [00:14<01:13,  2.21it/s]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 1, reducing to 1
 15%|█████████████████▏                                                                                                  | 28/189 [00:14<01:13,  2.18it/s]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 1, reducing to 1
 15%|█████████████████▊                                                                                                  | 29/189 [00:15<01:13,  2.18it/s]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 1, reducing to 1
[...]
```

This means the DeepSpeed loss scaler is unable to find a scaling coefficient to overcome loss overflow. To fix it, try a higher `initial_scale_power` value (32 usually works).

## Resources

DeepSpeed ZeRO is a powerful technology for training and loading very large models for inference with limited GPU resources, making it more accessible to everyone.


key: _node_content
string_value:
{"id_": "4a5a73f4-35d8-42a2-9667-6b85d5ffe303", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "af39070b-9107-4e33-8b63-6eb78f0af7cd", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "9408a27b37bc8218b970c759bc1d0b849eb9bb86f1b728bc154460e07619e3f6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "b521c736-88f0-4c0a-b5a8-51298ba5acc9", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/deepspeed/", "title": "DeepSpeed", "tokens": 14117, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "7a6df9c0a5eee03e25db33a3c12f1130d660c6e0952edea7d417b674e4c73584", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 55130, "end_char_idx": 57280, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
Rank 0 Skipping step. Attempted loss scale: 262144, reducing to 262144
  1%|▌                                                                                                                    | 1/189 [00:00<01:26,  2.17it/s]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 262144, reducing to 131072.0
  1%|█▏
 [...]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 1, reducing to 1
 14%|████████████████▌                                                                                                   | 27/189 [00:14<01:13,  2.21it/s]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 1, reducing to 1
 15%|█████████████████▏                                                                                                  | 28/189 [00:14<01:13,  2.18it/s]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 1, reducing to 1
 15%|█████████████████▊                                                                                                  | 29/189 [00:15<01:13,  2.18it/s]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 1, reducing to 1
[...]
```

This means the DeepSpeed loss scaler is unable to find a scaling coefficient to overcome loss overflow. To fix it, try a higher `initial_scale_power` value (32 usually works).

## Resources

DeepSpeed ZeRO is a powerful technology for training and loading very large models for inference with limited GPU resources, making it more accessible to everyone. To learn more about DeepSpeed, feel free to read the [blog posts](https://www.microsoft.com/en-us/research/search/?q=deepspeed), [documentation](https://www.deepspeed.ai/getting-started/), and [GitHub repository](https://github.com/microsoft/deepspeed). 

The following papers are also a great resource for learning more about ZeRO:

* [ZeRO: Memory Optimizations Toward Training Trillion Parameter Models](https://hf.co/papers/1910.02054)
* [ZeRO-Offload: Democratizing Billion-Scale Model Training](https://hf.co/papers/2101.06840)
* [ZeRO-Infinity: Breaking the GPU Memory Wall for Extreme Scale Deep Learning](https://hf.co/papers/2104.07857)


key: _node_content
string_value:
{"id_": "4e2d127b-08a8-4093-ab21-d9f4508fc5f8", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "ea616166-bf63-41ad-a22e-4274205c8666", "node_type": "1", "metadata": {}, "hash": "4bfdfc4013aa0effcda4de666acc0791525346a31cc0c328fa5f3c808473584d", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 0, "end_char_idx": 3402, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
# 🤗 Transformers

State-of-the-art Machine Learning for [PyTorch](https://pytorch.org/), [TensorFlow](https://www.tensorflow.org/), and [JAX](https://jax.readthedocs.io/en/latest/).

🤗 Transformers provides APIs and tools to easily download and train state-of-the-art pretrained models. Using pretrained models can reduce your compute costs, carbon footprint, and save you the time and resources required to train a model from scratch. These models support common tasks in different modalities, such as:

📝 **Natural Language Processing**: text classification, named entity recognition, question answering, language modeling, summarization, translation, multiple choice, and text generation.<br>
🖼️ **Computer Vision**: image classification, object detection, and segmentation.<br>
🗣️ **Audio**: automatic speech recognition and audio classification.<br>
🐙 **Multimodal**: table question answering, optical character recognition, information extraction from scanned documents, video classification, and visual question answering.

🤗 Transformers support framework interoperability between PyTorch, TensorFlow, and JAX. This provides the flexibility to use a different framework at each stage of a model's life; train a model in three lines of code in one framework, and load it for inference in another. Models can also be exported to a format like ONNX and TorchScript for deployment in production environments.

Join the growing community on the [Hub](https://huggingface.co/models), [forum](https://discuss.huggingface.co/), or [Discord](https://discord.com/invite/JfAtkvEtRb) today!

## If you are looking for custom support from the Hugging Face team

<a target="_blank" href="https://huggingface.co/support">
    <img alt="HuggingFace Expert Acceleration Program" src="https://cdn-media.huggingface.co/marketing/transformers/new-support-improved.png" style="width: 100%; max-width: 600px; border: 1px solid #eee; border-radius: 4px; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);">
</a>

## Contents

The documentation is organized into five sections:

- **GET STARTED** provides a quick tour of the library and installation instructions to get up and running.
- **TUTORIALS** are a great place to start if you're a beginner. This section will help you gain the basic skills you need to start using the library.
- **HOW-TO GUIDES** show you how to achieve a specific goal, like finetuning a pretrained model for language modeling or how to write and share a custom model.
- **CONCEPTUAL GUIDES** offers more discussion and explanation of the underlying concepts and ideas behind models, tasks, and the design philosophy of 🤗 Transformers.
- **API** describes all classes and functions:

  - **MAIN CLASSES** details the most important classes like configuration, model, tokenizer, and pipeline.
  - **MODELS** details the classes and functions related to each model implemented in the library.
  - **INTERNAL HELPERS** details utility classes and functions used internally.


## Supported models and frameworks

The table below represents the current support in the library for each of those models, whether they have a Python
tokenizer (called "slow"). A "fast" tokenizer backed by the 🤗 Tokenizers library, whether they have support in Jax (via
Flax), PyTorch, and/or TensorFlow.

<!--This table is updated automatically from the auto modules with _make fix-copies_. Do not update manually!-->

|


key: _node_content
string_value:
{"id_": "ea616166-bf63-41ad-a22e-4274205c8666", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "4e2d127b-08a8-4093-ab21-d9f4508fc5f8", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "6c4820e5d35a37c527a4ba42e79cf12ed5eea0ee99175a8669c99ff17f5d29e0", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "f05da85f-97e7-4040-b30c-45876624990f", "node_type": "1", "metadata": {}, "hash": "f3e1c3300fddfd503d4d6cb4dea47b2caab2f5c64f0d2229dba9fd8c35c8bde6", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 2980, "end_char_idx": 4432, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
## Supported models and frameworks

The table below represents the current support in the library for each of those models, whether they have a Python
tokenizer (called "slow"). A "fast" tokenizer backed by the 🤗 Tokenizers library, whether they have support in Jax (via
Flax), PyTorch, and/or TensorFlow.

<!--This table is updated automatically from the auto modules with _make fix-copies_. Do not update manually!-->

|                                  Model                                   | PyTorch support | TensorFlow support | Flax Support |
|:------------------------------------------------------------------------:|:---------------:|:------------------:|:------------:|
|                        [ALBERT](model_doc/albert)                        |       ✅        |         ✅         |      ✅      |
|                         [ALIGN](model_doc/align)                         |       ✅        |         ❌         |      ❌      |
|                       [AltCLIP](model_doc/altclip)                       |       ✅        |         ❌         |      ❌      |
| [Audio Spectrogram Transformer](model_doc/audio-spectrogram-transformer) |       ✅        |         ❌         |      ❌      |
|                    [Autoformer](model_doc/autoformer)                    |       ✅        |         ❌         |      ❌      |
|                          [Bark](model_doc/bark)                          |       ✅        |         ❌         |      ❌      |
|


key: _node_content
string_value:
{"id_": "f05da85f-97e7-4040-b30c-45876624990f", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "ea616166-bf63-41ad-a22e-4274205c8666", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "cd7983b7c46c5c964f0cc36208ac48d18c926d24968b72b900e00c29a1024b65", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "385b6322-324c-4c33-9d07-8ff675c3b070", "node_type": "1", "metadata": {}, "hash": "cfcc7f096d2e7bc70d529be4c4da353fc3e2de0548535ce94a080237c40b4868", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 3903, "end_char_idx": 4891, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|      ❌      |
|                       [AltCLIP](model_doc/altclip)                       |       ✅        |         ❌         |      ❌      |
| [Audio Spectrogram Transformer](model_doc/audio-spectrogram-transformer) |       ✅        |         ❌         |      ❌      |
|                    [Autoformer](model_doc/autoformer)                    |       ✅        |         ❌         |      ❌      |
|                          [Bark](model_doc/bark)                          |       ✅        |         ❌         |      ❌      |
|                          [BART](model_doc/bart)                          |       ✅        |         ✅         |      ✅      |
|                       [BARThez](model_doc/barthez)                       |       ✅        |         ✅         |      ✅      |
|                       [BARTpho](model_doc/bartpho)                       |       ✅        |         ✅         |      ✅      |
|                          [BEiT](model_doc/beit)                          |


key: _node_content
string_value:
{"id_": "385b6322-324c-4c33-9d07-8ff675c3b070", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "f05da85f-97e7-4040-b30c-45876624990f", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "d4105fdb8af76e9488a98f46a9f3ae0a9ea26a225bbb7a03d33725aa96286ce7", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "0b6ce02d-0302-4d75-b2ee-80546183bc3b", "node_type": "1", "metadata": {}, "hash": "0881277d3eb97ce8793973f75715bb6b2b47cb937b51b92d2c22012dbe679e1e", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 4422, "end_char_idx": 5380, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
❌      |
|                          [BART](model_doc/bart)                          |       ✅        |         ✅         |      ✅      |
|                       [BARThez](model_doc/barthez)                       |       ✅        |         ✅         |      ✅      |
|                       [BARTpho](model_doc/bartpho)                       |       ✅        |         ✅         |      ✅      |
|                          [BEiT](model_doc/beit)                          |       ✅        |         ❌         |      ✅      |
|                          [BERT](model_doc/bert)                          |       ✅        |         ✅         |      ✅      |
|               [Bert Generation](model_doc/bert-generation)               |       ✅        |         ❌         |      ❌      |
|                 [BertJapanese](model_doc/bert-japanese)                  |       ✅        |         ✅         |      ✅      |
|                      [BERTweet](model_doc/bertweet)


key: _node_content
string_value:
{"id_": "0b6ce02d-0302-4d75-b2ee-80546183bc3b", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "385b6322-324c-4c33-9d07-8ff675c3b070", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "02cb686e986b5c60b4bdd9f7dbae54a695b513ac15af2794790c0d2e8ab852e4", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "c75da204-ccc0-4ee7-a596-9b7d0f8bae02", "node_type": "1", "metadata": {}, "hash": "5c3e2363b670e447da6b96644ff5425e5fccfea6058b06611b99cff3a31a68d3", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 4890, "end_char_idx": 5840, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ❌         |      ✅      |
|                          [BERT](model_doc/bert)                          |       ✅        |         ✅         |      ✅      |
|               [Bert Generation](model_doc/bert-generation)               |       ✅        |         ❌         |      ❌      |
|                 [BertJapanese](model_doc/bert-japanese)                  |       ✅        |         ✅         |      ✅      |
|                      [BERTweet](model_doc/bertweet)                      |       ✅        |         ✅         |      ✅      |
|                      [BigBird](model_doc/big_bird)                       |       ✅        |         ❌         |      ✅      |
|               [BigBird-Pegasus](model_doc/bigbird_pegasus)               |       ✅        |         ❌         |      ❌      |
|                        [BioGpt](model_doc/biogpt)                        |       ✅        |         ❌         |      ❌      |
|


key: _node_content
string_value:
{"id_": "c75da204-ccc0-4ee7-a596-9b7d0f8bae02", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "0b6ce02d-0302-4d75-b2ee-80546183bc3b", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "03b092808dec06d9edc8dae18a2e17f8113864b446b6d178a09b928ee222f091", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "eaa06e08-1533-4145-b0fa-a524baab5645", "node_type": "1", "metadata": {}, "hash": "6a2d7d4c58e55f954f0043721dab23c16774e15b73f9cd4117ab930bc0ceafb0", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 5402, "end_char_idx": 6352, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ✅         |      ✅      |
|                      [BigBird](model_doc/big_bird)                       |       ✅        |         ❌         |      ✅      |
|               [BigBird-Pegasus](model_doc/bigbird_pegasus)               |       ✅        |         ❌         |      ❌      |
|                        [BioGpt](model_doc/biogpt)                        |       ✅        |         ❌         |      ❌      |
|                           [BiT](model_doc/bit)                           |       ✅        |         ❌         |      ❌      |
|                    [Blenderbot](model_doc/blenderbot)                    |       ✅        |         ✅         |      ✅      |
|              [BlenderbotSmall](model_doc/blenderbot-small)               |       ✅        |         ✅         |      ✅      |
|                          [BLIP](model_doc/blip)                          |       ✅        |         ✅         |      ❌      |
|


key: _node_content
string_value:
{"id_": "eaa06e08-1533-4145-b0fa-a524baab5645", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "c75da204-ccc0-4ee7-a596-9b7d0f8bae02", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "dc6fe086901208b3c75ebf1feb451cf4b56d5f734951fa7a0f5d74f3fb4c6695", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "32818832-f782-4335-8fff-bd7b88dd1ccf", "node_type": "1", "metadata": {}, "hash": "eb96d93c6d75e245eb944834a5fcd390a8988eecb80bffb1387a3f4b6f8c27f2", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 5867, "end_char_idx": 6828, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
[BiT](model_doc/bit)                           |       ✅        |         ❌         |      ❌      |
|                    [Blenderbot](model_doc/blenderbot)                    |       ✅        |         ✅         |      ✅      |
|              [BlenderbotSmall](model_doc/blenderbot-small)               |       ✅        |         ✅         |      ✅      |
|                          [BLIP](model_doc/blip)                          |       ✅        |         ✅         |      ❌      |
|                        [BLIP-2](model_doc/blip-2)                        |       ✅        |         ❌         |      ❌      |
|                         [BLOOM](model_doc/bloom)                         |       ✅        |         ❌         |      ✅      |
|                          [BORT](model_doc/bort)                          |       ✅        |         ✅         |      ✅      |
|                   [BridgeTower](model_doc/bridgetower)                   |       ✅        |


key: _node_content
string_value:
{"id_": "32818832-f782-4335-8fff-bd7b88dd1ccf", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "eaa06e08-1533-4145-b0fa-a524baab5645", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "a1fac17f337ced24511d947d3e4dfb0c2cca2e8e80096837e33b59328daee675", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "7b19e3b9-90bf-40dc-8b52-38c14cbc78ca", "node_type": "1", "metadata": {}, "hash": "7badec70133fa2e00c12fdc1d41e92e4ffdbd6c19f61d9615bc195b335de4ab7", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 6342, "end_char_idx": 7248, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
❌      |
|                        [BLIP-2](model_doc/blip-2)                        |       ✅        |         ❌         |      ❌      |
|                         [BLOOM](model_doc/bloom)                         |       ✅        |         ❌         |      ✅      |
|                          [BORT](model_doc/bort)                          |       ✅        |         ✅         |      ✅      |
|                   [BridgeTower](model_doc/bridgetower)                   |       ✅        |         ❌         |      ❌      |
|                          [BROS](model_doc/bros)                          |       ✅        |         ❌         |      ❌      |
|                          [ByT5](model_doc/byt5)                          |       ✅        |         ✅         |      ✅      |
|                     [CamemBERT](model_doc/camembert)                     |       ✅        |         ✅         |      ❌      |
|


key: _node_content
string_value:
{"id_": "7b19e3b9-90bf-40dc-8b52-38c14cbc78ca", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "32818832-f782-4335-8fff-bd7b88dd1ccf", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "cd0646406e1bd915568fab98525e8c231508a8956a6f2254146b8a1e5283ce78", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "03586232-d7d1-430f-b65a-504d80d5f312", "node_type": "1", "metadata": {}, "hash": "0c19da19691eba37cb3c356255c86741bc14522e283107ac14aecc0a6b9374c8", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 6810, "end_char_idx": 7760, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ❌         |      ❌      |
|                          [BROS](model_doc/bros)                          |       ✅        |         ❌         |      ❌      |
|                          [ByT5](model_doc/byt5)                          |       ✅        |         ✅         |      ✅      |
|                     [CamemBERT](model_doc/camembert)                     |       ✅        |         ✅         |      ❌      |
|                        [CANINE](model_doc/canine)                        |       ✅        |         ❌         |      ❌      |
|                     [Chameleon](model_doc/chameleon)                     |       ✅        |         ❌         |      ❌      |
|                  [Chinese-CLIP](model_doc/chinese_clip)                  |       ✅        |         ❌         |      ❌      |
|                          [CLAP](model_doc/clap)                          |       ✅        |         ❌         |      ❌      |
|


key: _node_content
string_value:
{"id_": "03586232-d7d1-430f-b65a-504d80d5f312", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "7b19e3b9-90bf-40dc-8b52-38c14cbc78ca", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "c5e75dace822acef9f284abef70c49104d89da50497ad9682cd0173f5a957528", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "1e1c870b-5eaa-4c2d-902f-e3ad68c51eb5", "node_type": "1", "metadata": {}, "hash": "184d4110da2bbb190fe8b98ccb41ebd35d6ffa17d9664580efd9d2fa3131a958", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 7272, "end_char_idx": 8227, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
[CANINE](model_doc/canine)                        |       ✅        |         ❌         |      ❌      |
|                     [Chameleon](model_doc/chameleon)                     |       ✅        |         ❌         |      ❌      |
|                  [Chinese-CLIP](model_doc/chinese_clip)                  |       ✅        |         ❌         |      ❌      |
|                          [CLAP](model_doc/clap)                          |       ✅        |         ❌         |      ❌      |
|                          [CLIP](model_doc/clip)                          |       ✅        |         ✅         |      ✅      |
|                       [CLIPSeg](model_doc/clipseg)                       |       ✅        |         ❌         |      ❌      |
|                          [CLVP](model_doc/clvp)                          |       ✅        |         ❌         |      ❌      |
|                       [CodeGen](model_doc/codegen)                       |       ✅


key: _node_content
string_value:
{"id_": "1e1c870b-5eaa-4c2d-902f-e3ad68c51eb5", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "03586232-d7d1-430f-b65a-504d80d5f312", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "61ed8922271e694ee2fea2a7c2ee3a0f0037c88d14a11dd7ebb32342fcdb809d", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "e180a379-08d6-427d-a64d-11297cab2d44", "node_type": "1", "metadata": {}, "hash": "d0c2b634fbb7962e0902c129477baafe80b0eabd49e4853a106ca576847aed8a", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 7750, "end_char_idx": 8731, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
❌      |
|                          [CLIP](model_doc/clip)                          |       ✅        |         ✅         |      ✅      |
|                       [CLIPSeg](model_doc/clipseg)                       |       ✅        |         ❌         |      ❌      |
|                          [CLVP](model_doc/clvp)                          |       ✅        |         ❌         |      ❌      |
|                       [CodeGen](model_doc/codegen)                       |       ✅        |         ❌         |      ❌      |
|                    [CodeLlama](model_doc/code_llama)                     |       ✅        |         ❌         |      ✅      |
|                        [Cohere](model_doc/cohere)                        |       ✅        |         ❌         |      ❌      |
|              [Conditional DETR](model_doc/conditional_detr)              |       ✅        |         ❌         |      ❌      |
|                      [ConvBERT](model_doc/convbert)                      |


key: _node_content
string_value:
{"id_": "e180a379-08d6-427d-a64d-11297cab2d44", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "1e1c870b-5eaa-4c2d-902f-e3ad68c51eb5", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "472dac0a6368d283a7bd1ac296703d4aa3b92cfa18ab6745cc06d4fc257b3965", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "eff35ed1-0f43-4e9f-8a7f-69d8ba572fc0", "node_type": "1", "metadata": {}, "hash": "87cb4498fb31971cd6bb5d5f1e41b0d047614d15744d685bea6dc172f68e96f7", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 8218, "end_char_idx": 9168, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ❌         |      ❌      |
|                    [CodeLlama](model_doc/code_llama)                     |       ✅        |         ❌         |      ✅      |
|                        [Cohere](model_doc/cohere)                        |       ✅        |         ❌         |      ❌      |
|              [Conditional DETR](model_doc/conditional_detr)              |       ✅        |         ❌         |      ❌      |
|                      [ConvBERT](model_doc/convbert)                      |       ✅        |         ✅         |      ❌      |
|                      [ConvNeXT](model_doc/convnext)                      |       ✅        |         ✅         |      ❌      |
|                    [ConvNeXTV2](model_doc/convnextv2)                    |       ✅        |         ✅         |      ❌      |
|                           [CPM](model_doc/cpm)                           |       ✅        |         ✅         |      ✅      |
|


key: _node_content
string_value:
{"id_": "eff35ed1-0f43-4e9f-8a7f-69d8ba572fc0", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "e180a379-08d6-427d-a64d-11297cab2d44", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "17d528c9339e5664f1d8d3648afbd65e1ae5bddea04661ee8a4ced80f77410a3", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "d4cb5541-7ff2-4fb6-8f61-ac6085e49570", "node_type": "1", "metadata": {}, "hash": "552790ff4a6e5de495e8c12f9e4be86b869bf54807e5ea9416c5c947adf4ffb7", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 8730, "end_char_idx": 9654, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ✅         |      ❌      |
|                      [ConvNeXT](model_doc/convnext)                      |       ✅        |         ✅         |      ❌      |
|                    [ConvNeXTV2](model_doc/convnextv2)                    |       ✅        |         ✅         |      ❌      |
|                           [CPM](model_doc/cpm)                           |       ✅        |         ✅         |      ✅      |
|                       [CPM-Ant](model_doc/cpmant)                        |       ✅        |         ❌         |      ❌      |
|                          [CTRL](model_doc/ctrl)                          |       ✅        |         ✅         |      ❌      |
|                           [CvT](model_doc/cvt)                           |       ✅        |         ✅         |      ❌      |
|                   [Data2VecAudio](model_doc/data2vec)                    |       ✅        |         ❌


key: _node_content
string_value:
{"id_": "d4cb5541-7ff2-4fb6-8f61-ac6085e49570", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "eff35ed1-0f43-4e9f-8a7f-69d8ba572fc0", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "d114baec457f08276ad887a1b38c07a2f2eed6c49fdc8e9fc434c0f2fab61de4", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "d173dfda-bd16-4beb-a1e9-f3ead2ee14fb", "node_type": "1", "metadata": {}, "hash": "fa06b260486b8c9770d8dbb51a5096ebbd3dfb31fee99d1a62582335f1b3688b", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 9191, "end_char_idx": 10139, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
[CPM-Ant](model_doc/cpmant)                        |       ✅        |         ❌         |      ❌      |
|                          [CTRL](model_doc/ctrl)                          |       ✅        |         ✅         |      ❌      |
|                           [CvT](model_doc/cvt)                           |       ✅        |         ✅         |      ❌      |
|                   [Data2VecAudio](model_doc/data2vec)                    |       ✅        |         ❌         |      ❌      |
|                    [Data2VecText](model_doc/data2vec)                    |       ✅        |         ❌         |      ❌      |
|                   [Data2VecVision](model_doc/data2vec)                   |       ✅        |         ✅         |      ❌      |
|                          [DBRX](model_doc/dbrx)                          |       ✅        |         ❌         |      ❌      |
|                       [DeBERTa](model_doc/deberta)                       |


key: _node_content
string_value:
{"id_": "d173dfda-bd16-4beb-a1e9-f3ead2ee14fb", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "d4cb5541-7ff2-4fb6-8f61-ac6085e49570", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "f8c63541609e4bc4c3467a8f1fb22743e49a3fa2c7eb7a849c3333f540b45e07", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "9d6b9774-00f9-4564-abb0-51305599f76e", "node_type": "1", "metadata": {}, "hash": "e4757b7c849f5d742cf670e2def72d801e85f6f2f74fd595666d2211adc83c90", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 9643, "end_char_idx": 10651, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|         ❌         |      ❌      |
|                    [Data2VecText](model_doc/data2vec)                    |       ✅        |         ❌         |      ❌      |
|                   [Data2VecVision](model_doc/data2vec)                   |       ✅        |         ✅         |      ❌      |
|                          [DBRX](model_doc/dbrx)                          |       ✅        |         ❌         |      ❌      |
|                       [DeBERTa](model_doc/deberta)                       |       ✅        |         ✅         |      ❌      |
|                    [DeBERTa-v2](model_doc/deberta-v2)                    |       ✅        |         ✅         |      ❌      |
|          [Decision Transformer](model_doc/decision_transformer)          |       ✅        |         ❌         |      ❌      |
|               [Deformable DETR](model_doc/deformable_detr)               |       ✅        |         ❌         |      ❌      |
|                          [DeiT](model_doc/deit)                          |


key: _node_content
string_value:
{"id_": "9d6b9774-00f9-4564-abb0-51305599f76e", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "d173dfda-bd16-4beb-a1e9-f3ead2ee14fb", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "f7e063fac2dbf8964f9d697ac72081e26535fb94120ca8babad3587ecf1399b3", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "bf137392-1de6-4b3b-a22c-c7f0d5c265ae", "node_type": "1", "metadata": {}, "hash": "080c03abe3f655b5b74f8ea38e5047a82c29099b05e8187da8f50847fb1f8a42", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 10138, "end_char_idx": 11136, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ✅         |      ❌      |
|                    [DeBERTa-v2](model_doc/deberta-v2)                    |       ✅        |         ✅         |      ❌      |
|          [Decision Transformer](model_doc/decision_transformer)          |       ✅        |         ❌         |      ❌      |
|               [Deformable DETR](model_doc/deformable_detr)               |       ✅        |         ❌         |      ❌      |
|                          [DeiT](model_doc/deit)                          |       ✅        |         ✅         |      ❌      |
|                        [DePlot](model_doc/deplot)                        |       ✅        |         ❌         |      ❌      |
|                [Depth Anything](model_doc/depth_anything)                |       ✅        |         ❌         |      ❌      |
|                          [DETA](model_doc/deta)                          |       ✅        |         ❌         |      ❌      |
|                          [DETR](model_doc/detr)


key: _node_content
string_value:
{"id_": "bf137392-1de6-4b3b-a22c-c7f0d5c265ae", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "9d6b9774-00f9-4564-abb0-51305599f76e", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "2e9048d2de89d850a7af9df06ee1368db0d2a7ac892667af0d9e7a99ecba53af", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "2448e0c4-c245-4889-be90-4a3dceeafe1f", "node_type": "1", "metadata": {}, "hash": "8aae107628738fcd436580786e738a7af85b52b8a7bfbd3169894b482c28ceda", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 10650, "end_char_idx": 11584, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ✅         |      ❌      |
|                        [DePlot](model_doc/deplot)                        |       ✅        |         ❌         |      ❌      |
|                [Depth Anything](model_doc/depth_anything)                |       ✅        |         ❌         |      ❌      |
|                          [DETA](model_doc/deta)                          |       ✅        |         ❌         |      ❌      |
|                          [DETR](model_doc/detr)                          |       ✅        |         ❌         |      ❌      |
|                      [DialoGPT](model_doc/dialogpt)                      |       ✅        |         ✅         |      ✅      |
|                         [DiNAT](model_doc/dinat)                         |       ✅        |         ❌         |      ❌      |
|                        [DINOv2](model_doc/dinov2)                        |       ✅        |         ❌         |


key: _node_content
string_value:
{"id_": "2448e0c4-c245-4889-be90-4a3dceeafe1f", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "bf137392-1de6-4b3b-a22c-c7f0d5c265ae", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "80373443468130e69b59a162149d2284e879a48a1996c598827007798be876b6", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "5aad3d56-576e-4517-b902-74b3598d9bf5", "node_type": "1", "metadata": {}, "hash": "598282fce85ece400c23cbbd703b547c1fc43225ffa6234a4023b361be6fe351", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 11114, "end_char_idx": 12031, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
[DETR](model_doc/detr)                          |       ✅        |         ❌         |      ❌      |
|                      [DialoGPT](model_doc/dialogpt)                      |       ✅        |         ✅         |      ✅      |
|                         [DiNAT](model_doc/dinat)                         |       ✅        |         ❌         |      ❌      |
|                        [DINOv2](model_doc/dinov2)                        |       ✅        |         ❌         |      ❌      |
|                    [DistilBERT](model_doc/distilbert)                    |       ✅        |         ✅         |      ✅      |
|                           [DiT](model_doc/dit)                           |       ✅        |         ❌         |      ✅      |
|                       [DonutSwin](model_doc/donut)                       |       ✅        |         ❌         |      ❌      |
|                           [DPR](model_doc/dpr)


key: _node_content
string_value:
{"id_": "5aad3d56-576e-4517-b902-74b3598d9bf5", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "2448e0c4-c245-4889-be90-4a3dceeafe1f", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "2b17810a30dbe1d74446876c92f57b4f51c5f28f90a73001d16de7baae8ad4de", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "408d4bf6-70a7-4c02-b624-e943f733e002", "node_type": "1", "metadata": {}, "hash": "9f6bed9cd232eb6592f321a1046f211e60104f00f42448449044a00bb7d5277a", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 11583, "end_char_idx": 12547, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|      ❌      |
|                    [DistilBERT](model_doc/distilbert)                    |       ✅        |         ✅         |      ✅      |
|                           [DiT](model_doc/dit)                           |       ✅        |         ❌         |      ✅      |
|                       [DonutSwin](model_doc/donut)                       |       ✅        |         ❌         |      ❌      |
|                           [DPR](model_doc/dpr)                           |       ✅        |         ✅         |      ❌      |
|                           [DPT](model_doc/dpt)                           |       ✅        |         ❌         |      ❌      |
|               [EfficientFormer](model_doc/efficientformer)               |       ✅        |         ✅         |      ❌      |
|                  [EfficientNet](model_doc/efficientnet)                  |       ✅        |         ❌         |      ❌      |
|                       [ELECTRA](model_doc/electra)


key: _node_content
string_value:
{"id_": "408d4bf6-70a7-4c02-b624-e943f733e002", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "5aad3d56-576e-4517-b902-74b3598d9bf5", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "f368f05553fb9df393274274accc7ba5a143191b708f69e28474c11cbce6a387", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "9a516c57-c5b6-434f-a7fe-a412ad59362b", "node_type": "1", "metadata": {}, "hash": "1760fd3a27a7643906be60e226886352f43cb59fa2ea213719cdc8cd62bd88b8", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 12058, "end_char_idx": 13008, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ✅         |      ❌      |
|                           [DPT](model_doc/dpt)                           |       ✅        |         ❌         |      ❌      |
|               [EfficientFormer](model_doc/efficientformer)               |       ✅        |         ✅         |      ❌      |
|                  [EfficientNet](model_doc/efficientnet)                  |       ✅        |         ❌         |      ❌      |
|                       [ELECTRA](model_doc/electra)                       |       ✅        |         ✅         |      ✅      |
|                       [EnCodec](model_doc/encodec)                       |       ✅        |         ❌         |      ❌      |
|               [Encoder decoder](model_doc/encoder-decoder)               |       ✅        |         ✅         |      ✅      |
|                         [ERNIE](model_doc/ernie)                         |       ✅        |         ❌         |      ❌      |
|


key: _node_content
string_value:
{"id_": "9a516c57-c5b6-434f-a7fe-a412ad59362b", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "408d4bf6-70a7-4c02-b624-e943f733e002", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "bea78e64411705e29fbe9d2bcf143c001b15339a952c38929265c2971114f81b", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "100786b6-7890-4ad5-81b1-bf0ccfc57630", "node_type": "1", "metadata": {}, "hash": "4ab85efd3121093bcd3c8c2375ba25cff8669e5ba477f2e3ecfd36906214e535", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 12570, "end_char_idx": 13520, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ✅         |      ✅      |
|                       [EnCodec](model_doc/encodec)                       |       ✅        |         ❌         |      ❌      |
|               [Encoder decoder](model_doc/encoder-decoder)               |       ✅        |         ✅         |      ✅      |
|                         [ERNIE](model_doc/ernie)                         |       ✅        |         ❌         |      ❌      |
|                       [ErnieM](model_doc/ernie_m)                        |       ✅        |         ❌         |      ❌      |
|                           [ESM](model_doc/esm)                           |       ✅        |         ✅         |      ❌      |
|              [FairSeq Machine-Translation](model_doc/fsmt)               |       ✅        |         ❌         |      ❌      |
|                        [Falcon](model_doc/falcon)                        |       ✅        |         ❌         |      ❌      |
|


key: _node_content
string_value:
{"id_": "100786b6-7890-4ad5-81b1-bf0ccfc57630", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "9a516c57-c5b6-434f-a7fe-a412ad59362b", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "7276aa95680c7731c2fd16ac4d138308c054f68244f13ce71da1392be96fd706", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "d20ce911-bb82-4340-a39c-1d31ba7ac6db", "node_type": "1", "metadata": {}, "hash": "f4737e8691434b2c03a672feba5d74f4f52705436642cee1b1befa3cb787a075", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 13031, "end_char_idx": 14016, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
[ErnieM](model_doc/ernie_m)                        |       ✅        |         ❌         |      ❌      |
|                           [ESM](model_doc/esm)                           |       ✅        |         ✅         |      ❌      |
|              [FairSeq Machine-Translation](model_doc/fsmt)               |       ✅        |         ❌         |      ❌      |
|                        [Falcon](model_doc/falcon)                        |       ✅        |         ❌         |      ❌      |
|         [FastSpeech2Conformer](model_doc/fastspeech2_conformer)          |       ✅        |         ❌         |      ❌      |
|                       [FLAN-T5](model_doc/flan-t5)                       |       ✅        |         ✅         |      ✅      |
|                      [FLAN-UL2](model_doc/flan-ul2)                      |       ✅        |         ✅         |      ✅      |
|                      [FlauBERT](model_doc/flaubert)                      |       ✅        |         ✅         |


key: _node_content
string_value:
{"id_": "d20ce911-bb82-4340-a39c-1d31ba7ac6db", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "100786b6-7890-4ad5-81b1-bf0ccfc57630", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "30c0c36c67f559c5e904fc52618e50f77085f4efd277843e7f4385f082574405", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "a2fe0fa0-b330-4dd4-a147-edc58fc71235", "node_type": "1", "metadata": {}, "hash": "c7de25d9b25eaae55c1eb8ea34430258ac323f610c2ba92d870b32a5caccff3f", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 13510, "end_char_idx": 14499, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
❌      |
|         [FastSpeech2Conformer](model_doc/fastspeech2_conformer)          |       ✅        |         ❌         |      ❌      |
|                       [FLAN-T5](model_doc/flan-t5)                       |       ✅        |         ✅         |      ✅      |
|                      [FLAN-UL2](model_doc/flan-ul2)                      |       ✅        |         ✅         |      ✅      |
|                      [FlauBERT](model_doc/flaubert)                      |       ✅        |         ✅         |      ❌      |
|                         [FLAVA](model_doc/flava)                         |       ✅        |         ❌         |      ❌      |
|                          [FNet](model_doc/fnet)                          |       ✅        |         ❌         |      ❌      |
|                      [FocalNet](model_doc/focalnet)                      |       ✅        |         ❌         |      ❌      |
|                  [Funnel Transformer](model_doc/funnel)                  |       ✅


key: _node_content
string_value:
{"id_": "a2fe0fa0-b330-4dd4-a147-edc58fc71235", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "d20ce911-bb82-4340-a39c-1d31ba7ac6db", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "79ed7dce4f494487ffe0189277c0ea7118348fc4acc9ba9c5560e565d9269169", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "5bcee220-5153-4def-a260-f8cc170c3a7c", "node_type": "1", "metadata": {}, "hash": "068e32a687dbf9504f9d70b32e4ae4274d42a8426c530688065dcaba3594a5b0", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 14005, "end_char_idx": 14928, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
✅         |      ❌      |
|                         [FLAVA](model_doc/flava)                         |       ✅        |         ❌         |      ❌      |
|                          [FNet](model_doc/fnet)                          |       ✅        |         ❌         |      ❌      |
|                      [FocalNet](model_doc/focalnet)                      |       ✅        |         ❌         |      ❌      |
|                  [Funnel Transformer](model_doc/funnel)                  |       ✅        |         ✅         |      ❌      |
|                          [Fuyu](model_doc/fuyu)                          |       ✅        |         ❌         |      ❌      |
|                         [Gemma](model_doc/gemma)                         |       ✅        |         ❌         |      ✅      |
|                        [Gemma2](model_doc/gemma2)                        |       ✅        |         ❌         |      ❌      |
|


key: _node_content
string_value:
{"id_": "5bcee220-5153-4def-a260-f8cc170c3a7c", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "a2fe0fa0-b330-4dd4-a147-edc58fc71235", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "1344e46e0ca28eaf8d17caa2af20b22911ed681355b59f1fca837d16b157cfeb", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "cd6eb256-1e2f-448c-a402-24b553a78d45", "node_type": "1", "metadata": {}, "hash": "a313d1813377dd88f60909e533d14526912bbc1f8c87a0f2a1728667923a23cf", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 14490, "end_char_idx": 15414, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ✅         |      ❌      |
|                          [Fuyu](model_doc/fuyu)                          |       ✅        |         ❌         |      ❌      |
|                         [Gemma](model_doc/gemma)                         |       ✅        |         ❌         |      ✅      |
|                        [Gemma2](model_doc/gemma2)                        |       ✅        |         ❌         |      ❌      |
|                           [GIT](model_doc/git)                           |       ✅        |         ❌         |      ❌      |
|                          [GLPN](model_doc/glpn)                          |       ✅        |         ❌         |      ❌      |
|                       [GPT Neo](model_doc/gpt_neo)                       |       ✅        |         ❌         |      ✅      |
|                      [GPT NeoX](model_doc/gpt_neox)                      |       ✅        |         ❌


key: _node_content
string_value:
{"id_": "cd6eb256-1e2f-448c-a402-24b553a78d45", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "5bcee220-5153-4def-a260-f8cc170c3a7c", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "1d0465563a34219190b28179112ae5a12f90c43d72fc16f60734b64d594b2f51", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "aa379994-3b1d-4eb0-9442-809ab17e4a17", "node_type": "1", "metadata": {}, "hash": "e14bd0c403b19021170ff21e28a8f7ed1b673ec706b7b312fe79d4b5264cf023", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 14955, "end_char_idx": 15899, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
[GIT](model_doc/git)                           |       ✅        |         ❌         |      ❌      |
|                          [GLPN](model_doc/glpn)                          |       ✅        |         ❌         |      ❌      |
|                       [GPT Neo](model_doc/gpt_neo)                       |       ✅        |         ❌         |      ✅      |
|                      [GPT NeoX](model_doc/gpt_neox)                      |       ✅        |         ❌         |      ❌      |
|             [GPT NeoX Japanese](model_doc/gpt_neox_japanese)             |       ✅        |         ❌         |      ❌      |
|                         [GPT-J](model_doc/gptj)                          |       ✅        |         ✅         |      ✅      |
|                       [GPT-Sw3](model_doc/gpt-sw3)                       |       ✅        |         ✅         |      ✅      |
|                   [GPTBigCode](model_doc/gpt_bigcode)                    |


key: _node_content
string_value:
{"id_": "aa379994-3b1d-4eb0-9442-809ab17e4a17", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "cd6eb256-1e2f-448c-a402-24b553a78d45", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "a39ba45f9243a85d1270665dc6f613c3efc460a2345fbc82385eba25cf62a2e1", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "ffc49f9b-87b7-47a1-acd0-3e2f1df94dc9", "node_type": "1", "metadata": {}, "hash": "68485efc83ef99916057bfd557084223b0acba986c1a2a462821c214917be0d7", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 15403, "end_char_idx": 16411, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|         ❌         |      ❌      |
|             [GPT NeoX Japanese](model_doc/gpt_neox_japanese)             |       ✅        |         ❌         |      ❌      |
|                         [GPT-J](model_doc/gptj)                          |       ✅        |         ✅         |      ✅      |
|                       [GPT-Sw3](model_doc/gpt-sw3)                       |       ✅        |         ✅         |      ✅      |
|                   [GPTBigCode](model_doc/gpt_bigcode)                    |       ✅        |         ❌         |      ❌      |
|               [GPTSAN-japanese](model_doc/gptsan-japanese)               |       ✅        |         ❌         |      ❌      |
|                    [Graphormer](model_doc/graphormer)                    |       ✅        |         ❌         |      ❌      |
|                [Grounding DINO](model_doc/grounding-dino)                |       ✅        |         ❌         |      ❌      |
|                      [GroupViT](model_doc/groupvit)                      |


key: _node_content
string_value:
{"id_": "ffc49f9b-87b7-47a1-acd0-3e2f1df94dc9", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "aa379994-3b1d-4eb0-9442-809ab17e4a17", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "54bf354f24982ca03d22e8ee08a4c7cd33185d76e48918f14f8256ba8d23fbff", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "0a21167d-d24b-41d0-965e-a2edc3088bb7", "node_type": "1", "metadata": {}, "hash": "626145d72fc2fbc224b39a1c668d68bb8f8c76086c68e8e0c9a51bda9bf50c26", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 15898, "end_char_idx": 16848, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ❌         |      ❌      |
|               [GPTSAN-japanese](model_doc/gptsan-japanese)               |       ✅        |         ❌         |      ❌      |
|                    [Graphormer](model_doc/graphormer)                    |       ✅        |         ❌         |      ❌      |
|                [Grounding DINO](model_doc/grounding-dino)                |       ✅        |         ❌         |      ❌      |
|                      [GroupViT](model_doc/groupvit)                      |       ✅        |         ✅         |      ❌      |
|                       [HerBERT](model_doc/herbert)                       |       ✅        |         ✅         |      ✅      |
|                         [Hiera](model_doc/hiera)                         |       ✅        |         ❌         |      ❌      |
|                        [Hubert](model_doc/hubert)                        |       ✅        |         ✅         |      ❌      |
|


key: _node_content
string_value:
{"id_": "0a21167d-d24b-41d0-965e-a2edc3088bb7", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "ffc49f9b-87b7-47a1-acd0-3e2f1df94dc9", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "df6247128001b8431e21f8486d85bdc94667b7e1d98f2f16f77a5839ba15f99f", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "1f64dfe4-4d7f-404f-9443-c8fdae325996", "node_type": "1", "metadata": {}, "hash": "2630aff453dc601c309344e856c5ef72efff26e2a899874d417b46f7c8a83c08", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 16410, "end_char_idx": 17344, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ✅         |      ❌      |
|                       [HerBERT](model_doc/herbert)                       |       ✅        |         ✅         |      ✅      |
|                         [Hiera](model_doc/hiera)                         |       ✅        |         ❌         |      ❌      |
|                        [Hubert](model_doc/hubert)                        |       ✅        |         ✅         |      ❌      |
|                        [I-BERT](model_doc/ibert)                         |       ✅        |         ❌         |      ❌      |
|                       [IDEFICS](model_doc/idefics)                       |       ✅        |         ✅         |      ❌      |
|                      [Idefics2](model_doc/idefics2)                      |       ✅        |         ❌         |      ❌      |
|                      [ImageGPT](model_doc/imagegpt)                      |       ✅        |         ❌         |


key: _node_content
string_value:
{"id_": "1f64dfe4-4d7f-404f-9443-c8fdae325996", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "0a21167d-d24b-41d0-965e-a2edc3088bb7", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "b9330e3b8c8892049c1c1abee46e7f9bf22be673921d6b09602a64261629f891", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "e306e078-7083-49cf-b33b-f3806857a673", "node_type": "1", "metadata": {}, "hash": "1c24e477def9b1da483e91f29ae03ab9c9682a4e9c85cb32895169dbfaaed6c5", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 16872, "end_char_idx": 17846, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
[I-BERT](model_doc/ibert)                         |       ✅        |         ❌         |      ❌      |
|                       [IDEFICS](model_doc/idefics)                       |       ✅        |         ✅         |      ❌      |
|                      [Idefics2](model_doc/idefics2)                      |       ✅        |         ❌         |      ❌      |
|                      [ImageGPT](model_doc/imagegpt)                      |       ✅        |         ❌         |      ❌      |
|                      [Informer](model_doc/informer)                      |       ✅        |         ❌         |      ❌      |
|                  [InstructBLIP](model_doc/instructblip)                  |       ✅        |         ❌         |      ❌      |
|             [InstructBlipVideo](model_doc/instructblipvideo)             |       ✅        |         ❌         |      ❌      |
|                         [Jamba](model_doc/jamba)                         |       ✅        |         ❌


key: _node_content
string_value:
{"id_": "e306e078-7083-49cf-b33b-f3806857a673", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "1f64dfe4-4d7f-404f-9443-c8fdae325996", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "3027f366de111db920ea81fb3798244a2a33df7e211e3b8a5e3d8b26e6ebe411", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "a0dce7d6-a42d-437f-8b06-972739305bf2", "node_type": "1", "metadata": {}, "hash": "6fcb5b0d14d255a171308e8d524f0ee20007ac59c6b3ee7f63e9203e0932feac", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 17333, "end_char_idx": 18308, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
❌         |      ❌      |
|                      [Informer](model_doc/informer)                      |       ✅        |         ❌         |      ❌      |
|                  [InstructBLIP](model_doc/instructblip)                  |       ✅        |         ❌         |      ❌      |
|             [InstructBlipVideo](model_doc/instructblipvideo)             |       ✅        |         ❌         |      ❌      |
|                         [Jamba](model_doc/jamba)                         |       ✅        |         ❌         |      ❌      |
|                        [JetMoe](model_doc/jetmoe)                        |       ✅        |         ❌         |      ❌      |
|                       [Jukebox](model_doc/jukebox)                       |       ✅        |         ❌         |      ❌      |
|                      [KOSMOS-2](model_doc/kosmos-2)                      |       ✅        |         ❌         |      ❌      |
|                      [LayoutLM](model_doc/layoutlm)


key: _node_content
string_value:
{"id_": "a0dce7d6-a42d-437f-8b06-972739305bf2", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "e306e078-7083-49cf-b33b-f3806857a673", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "d4b8e9b4d698fb737ac12143d5ee9391166a0813f02851bdc18169d650eb72c8", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "e89849cb-9d46-4893-a5e7-331514ddc641", "node_type": "1", "metadata": {}, "hash": "b9db103746e3e0d423fd1836b4b16a5d7e0e7466e74ec54ee2ae8752843cf484", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 17835, "end_char_idx": 18768, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|         ❌         |      ❌      |
|                        [JetMoe](model_doc/jetmoe)                        |       ✅        |         ❌         |      ❌      |
|                       [Jukebox](model_doc/jukebox)                       |       ✅        |         ❌         |      ❌      |
|                      [KOSMOS-2](model_doc/kosmos-2)                      |       ✅        |         ❌         |      ❌      |
|                      [LayoutLM](model_doc/layoutlm)                      |       ✅        |         ✅         |      ❌      |
|                    [LayoutLMv2](model_doc/layoutlmv2)                    |       ✅        |         ❌         |      ❌      |
|                    [LayoutLMv3](model_doc/layoutlmv3)                    |       ✅        |         ✅         |      ❌      |
|                     [LayoutXLM](model_doc/layoutxlm)                     |       ✅        |         ❌         |      ❌      |
|


key: _node_content
string_value:
{"id_": "e89849cb-9d46-4893-a5e7-331514ddc641", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "a0dce7d6-a42d-437f-8b06-972739305bf2", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "fff180c19bfae8a053d2a2ba6785f3335ccc0772aac5d6a14d756a2facbd87db", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "02b4094c-0c6d-452e-b011-6aff81e9923e", "node_type": "1", "metadata": {}, "hash": "bc89d5661821b67cb351fd8d8befd5ea0803eac86a9ceceac7798f72e80a82ac", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 18330, "end_char_idx": 19244, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ✅         |      ❌      |
|                    [LayoutLMv2](model_doc/layoutlmv2)                    |       ✅        |         ❌         |      ❌      |
|                    [LayoutLMv3](model_doc/layoutlmv3)                    |       ✅        |         ✅         |      ❌      |
|                     [LayoutXLM](model_doc/layoutxlm)                     |       ✅        |         ❌         |      ❌      |
|                           [LED](model_doc/led)                           |       ✅        |         ✅         |      ❌      |
|                         [LeViT](model_doc/levit)                         |       ✅        |         ❌         |      ❌      |
|                          [LiLT](model_doc/lilt)                          |       ✅        |         ❌         |      ❌      |
|                         [LLaMA](model_doc/llama)                         |       ✅        |


key: _node_content
string_value:
{"id_": "02b4094c-0c6d-452e-b011-6aff81e9923e", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "e89849cb-9d46-4893-a5e7-331514ddc641", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "6616aa2ef48dc9b383e1efa5ebaf814d71a8715381d605249425e97d17ad04db", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "8e5561a2-e000-4e07-a22a-8004ea1a02ec", "node_type": "1", "metadata": {}, "hash": "b2207f6653c8e1df002f76bf00cc7d7c36e05ab47915c14e8286dea7e0320df7", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 18795, "end_char_idx": 19718, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
[LED](model_doc/led)                           |       ✅        |         ✅         |      ❌      |
|                         [LeViT](model_doc/levit)                         |       ✅        |         ❌         |      ❌      |
|                          [LiLT](model_doc/lilt)                          |       ✅        |         ❌         |      ❌      |
|                         [LLaMA](model_doc/llama)                         |       ✅        |         ❌         |      ✅      |
|                        [Llama2](model_doc/llama2)                        |       ✅        |         ❌         |      ✅      |
|                        [Llama3](model_doc/llama3)                        |       ✅        |         ❌         |      ✅      |
|                         [LLaVa](model_doc/llava)                         |       ✅        |         ❌         |      ❌      |
|                    [LLaVA-NeXT](model_doc/llava_next)


key: _node_content
string_value:
{"id_": "8e5561a2-e000-4e07-a22a-8004ea1a02ec", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "02b4094c-0c6d-452e-b011-6aff81e9923e", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "da4d09f4d66033b5a1da95651a7ce7b000b2a5cb8c7913eb6ffc190b0f1fb552", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "b451dfa1-a747-47c2-ae71-9a84bed7ce22", "node_type": "1", "metadata": {}, "hash": "81fe37a0837d007279073266e99673ebbee2b45e51812ae621211e8384ea0ea6", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 19243, "end_char_idx": 20176, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|         ❌         |      ✅      |
|                        [Llama2](model_doc/llama2)                        |       ✅        |         ❌         |      ✅      |
|                        [Llama3](model_doc/llama3)                        |       ✅        |         ❌         |      ✅      |
|                         [LLaVa](model_doc/llava)                         |       ✅        |         ❌         |      ❌      |
|                    [LLaVA-NeXT](model_doc/llava_next)                    |       ✅        |         ❌         |      ❌      |
|              [LLaVa-NeXT-Video](model_doc/llava-next-video)              |       ✅        |         ❌         |      ❌      |
|                    [Longformer](model_doc/longformer)                    |       ✅        |         ✅         |      ❌      |
|                        [LongT5](model_doc/longt5)                        |       ✅        |         ❌         |      ✅      |
|


key: _node_content
string_value:
{"id_": "b451dfa1-a747-47c2-ae71-9a84bed7ce22", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "8e5561a2-e000-4e07-a22a-8004ea1a02ec", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "f012714b499a3638df6b4706ae621183ea2c7c72c9a69d89eb2bd9cba10a355a", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "77edc936-a24a-4b35-ab78-d86783a1238e", "node_type": "1", "metadata": {}, "hash": "06d3e8dfec96df642d4f1254417f454672e0fbcd32215fbcb117073858e2a3bf", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 19738, "end_char_idx": 20662, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ❌         |      ❌      |
|              [LLaVa-NeXT-Video](model_doc/llava-next-video)              |       ✅        |         ❌         |      ❌      |
|                    [Longformer](model_doc/longformer)                    |       ✅        |         ✅         |      ❌      |
|                        [LongT5](model_doc/longt5)                        |       ✅        |         ❌         |      ✅      |
|                          [LUKE](model_doc/luke)                          |       ✅        |         ❌         |      ❌      |
|                        [LXMERT](model_doc/lxmert)                        |       ✅        |         ✅         |      ❌      |
|                        [M-CTC-T](model_doc/mctct)                        |       ✅        |         ❌         |      ❌      |
|                       [M2M100](model_doc/m2m_100)                        |       ✅        |         ❌


key: _node_content
string_value:
{"id_": "77edc936-a24a-4b35-ab78-d86783a1238e", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "b451dfa1-a747-47c2-ae71-9a84bed7ce22", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "10cfae912b68bc03d5427a0e98cf76cbb8bade270a1eff29640eb67e7cad17e8", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "5d8e60dd-902e-438d-8f71-ea2999340218", "node_type": "1", "metadata": {}, "hash": "dbce5d4523e4f4137476413fc3b8e615f8d594afd363a4a3880c6501a1d43fcd", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 20202, "end_char_idx": 21124, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
[LUKE](model_doc/luke)                          |       ✅        |         ❌         |      ❌      |
|                        [LXMERT](model_doc/lxmert)                        |       ✅        |         ✅         |      ❌      |
|                        [M-CTC-T](model_doc/mctct)                        |       ✅        |         ❌         |      ❌      |
|                       [M2M100](model_doc/m2m_100)                        |       ✅        |         ❌         |      ❌      |
|                    [MADLAD-400](model_doc/madlad-400)                    |       ✅        |         ✅         |      ✅      |
|                         [Mamba](model_doc/mamba)                         |       ✅        |         ❌         |      ❌      |
|                        [Marian](model_doc/marian)                        |       ✅        |         ✅         |      ✅      |
|                      [MarkupLM](model_doc/markuplm)


key: _node_content
string_value:
{"id_": "5d8e60dd-902e-438d-8f71-ea2999340218", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "77edc936-a24a-4b35-ab78-d86783a1238e", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "e70270125191585dca228d7ad5e359fef7fd1be4406a6c8a75a8d314df9f0d49", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "7544cc7f-8335-4b85-9c76-2af325b9ddef", "node_type": "1", "metadata": {}, "hash": "3331652e59e7ecd9e6d743f00b668341b5d40a4d94a2bb7c32a30b3601aa2164", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 20661, "end_char_idx": 21584, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
❌         |      ❌      |
|                    [MADLAD-400](model_doc/madlad-400)                    |       ✅        |         ✅         |      ✅      |
|                         [Mamba](model_doc/mamba)                         |       ✅        |         ❌         |      ❌      |
|                        [Marian](model_doc/marian)                        |       ✅        |         ✅         |      ✅      |
|                      [MarkupLM](model_doc/markuplm)                      |       ✅        |         ❌         |      ❌      |
|                   [Mask2Former](model_doc/mask2former)                   |       ✅        |         ❌         |      ❌      |
|                    [MaskFormer](model_doc/maskformer)                    |       ✅        |         ❌         |      ❌      |
|                        [MatCha](model_doc/matcha)                        |       ✅        |         ❌         |      ❌      |
|


key: _node_content
string_value:
{"id_": "7544cc7f-8335-4b85-9c76-2af325b9ddef", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "5d8e60dd-902e-438d-8f71-ea2999340218", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "1a1ff2901c23b59aa962e5e5003c556ee290b4c40c02ad2e8a86890f5427ae93", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "9f361cdb-aa53-4dc5-9975-4249333a4860", "node_type": "1", "metadata": {}, "hash": "cccb81a4cce51f128141bb891f52424fc86dc8fcb9e913956ab69635643a447a", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 21146, "end_char_idx": 22080, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ❌         |      ❌      |
|                   [Mask2Former](model_doc/mask2former)                   |       ✅        |         ❌         |      ❌      |
|                    [MaskFormer](model_doc/maskformer)                    |       ✅        |         ❌         |      ❌      |
|                        [MatCha](model_doc/matcha)                        |       ✅        |         ❌         |      ❌      |
|                         [mBART](model_doc/mbart)                         |       ✅        |         ✅         |      ✅      |
|                      [mBART-50](model_doc/mbart50)                       |       ✅        |         ✅         |      ✅      |
|                          [MEGA](model_doc/mega)                          |       ✅        |         ❌         |      ❌      |
|                 [Megatron-BERT](model_doc/megatron-bert)                 |       ✅        |         ❌         |


key: _node_content
string_value:
{"id_": "9f361cdb-aa53-4dc5-9975-4249333a4860", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "7544cc7f-8335-4b85-9c76-2af325b9ddef", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "db6d0eb52e00ccf9e37344fe5257919ef88252be20be9bbdb1aea3157cfc935b", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "7891bc9a-4c2e-4ffc-ba49-1c8ceec640bc", "node_type": "1", "metadata": {}, "hash": "2138513320bd38354b73ef063de1ff904c93f0a89036fd33646a8a8f3c760dba", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 21609, "end_char_idx": 22563, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
[mBART](model_doc/mbart)                         |       ✅        |         ✅         |      ✅      |
|                      [mBART-50](model_doc/mbart50)                       |       ✅        |         ✅         |      ✅      |
|                          [MEGA](model_doc/mega)                          |       ✅        |         ❌         |      ❌      |
|                 [Megatron-BERT](model_doc/megatron-bert)                 |       ✅        |         ❌         |      ❌      |
|                 [Megatron-GPT2](model_doc/megatron_gpt2)                 |       ✅        |         ✅         |      ✅      |
|                       [MGP-STR](model_doc/mgp-str)                       |       ✅        |         ❌         |      ❌      |
|                       [Mistral](model_doc/mistral)                       |       ✅        |         ✅         |      ✅      |
|                       [Mixtral](model_doc/mixtral)                       |       ✅


key: _node_content
string_value:
{"id_": "7891bc9a-4c2e-4ffc-ba49-1c8ceec640bc", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "9f361cdb-aa53-4dc5-9975-4249333a4860", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "7723cfde10126efe6343128f13ca2c86b9078de535dbbbfe0eed1a93c980c50f", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "37628c71-7ff4-41bd-9f6d-bf2eeb1535af", "node_type": "1", "metadata": {}, "hash": "105e168d19b6656c9c7898e641224c477d5049cfc6e4a81d6e0f859b57c11a03", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 22079, "end_char_idx": 23047, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|      ❌      |
|                 [Megatron-GPT2](model_doc/megatron_gpt2)                 |       ✅        |         ✅         |      ✅      |
|                       [MGP-STR](model_doc/mgp-str)                       |       ✅        |         ❌         |      ❌      |
|                       [Mistral](model_doc/mistral)                       |       ✅        |         ✅         |      ✅      |
|                       [Mixtral](model_doc/mixtral)                       |       ✅        |         ❌         |      ❌      |
|                         [mLUKE](model_doc/mluke)                         |       ✅        |         ❌         |      ❌      |
|                           [MMS](model_doc/mms)                           |       ✅        |         ✅         |      ✅      |
|                    [MobileBERT](model_doc/mobilebert)                    |       ✅        |         ✅         |      ❌      |
|                  [MobileNetV1](model_doc/mobilenet_v1)


key: _node_content
string_value:
{"id_": "37628c71-7ff4-41bd-9f6d-bf2eeb1535af", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "7891bc9a-4c2e-4ffc-ba49-1c8ceec640bc", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "660752efcb9340b5b99fc63b84e41e629d3643b66685c96b0c3464349e6bc2d1", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "98dabb8c-c846-46cb-9bd5-c06d5d77b400", "node_type": "1", "metadata": {}, "hash": "a1a0f3584dedb42f58e0262ab0e5c33ce49a774dbd4e35b203195585fc54f3c9", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 22554, "end_char_idx": 23504, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ❌         |      ❌      |
|                         [mLUKE](model_doc/mluke)                         |       ✅        |         ❌         |      ❌      |
|                           [MMS](model_doc/mms)                           |       ✅        |         ✅         |      ✅      |
|                    [MobileBERT](model_doc/mobilebert)                    |       ✅        |         ✅         |      ❌      |
|                  [MobileNetV1](model_doc/mobilenet_v1)                   |       ✅        |         ❌         |      ❌      |
|                  [MobileNetV2](model_doc/mobilenet_v2)                   |       ✅        |         ❌         |      ❌      |
|                     [MobileViT](model_doc/mobilevit)                     |       ✅        |         ✅         |      ❌      |
|                   [MobileViTV2](model_doc/mobilevitv2)                   |       ✅        |         ❌         |      ❌      |
|


key: _node_content
string_value:
{"id_": "98dabb8c-c846-46cb-9bd5-c06d5d77b400", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "37628c71-7ff4-41bd-9f6d-bf2eeb1535af", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "3515e25fed113be6d04dc39cf9d39ae4c7d714f0815d4fc64bf807b0f2a8e3fe", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "c7b2e989-fc0b-4ac4-adfe-09a6a4b6389a", "node_type": "1", "metadata": {}, "hash": "b99228cbcdef0040e3919b7c8f5f9faa9c75f2973163931e010125c3a6cefb15", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 23066, "end_char_idx": 23990, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ❌         |      ❌      |
|                  [MobileNetV2](model_doc/mobilenet_v2)                   |       ✅        |         ❌         |      ❌      |
|                     [MobileViT](model_doc/mobilevit)                     |       ✅        |         ✅         |      ❌      |
|                   [MobileViTV2](model_doc/mobilevitv2)                   |       ✅        |         ❌         |      ❌      |
|                         [MPNet](model_doc/mpnet)                         |       ✅        |         ✅         |      ❌      |
|                           [MPT](model_doc/mpt)                           |       ✅        |         ❌         |      ❌      |
|                           [MRA](model_doc/mra)                           |       ✅        |         ❌         |      ❌      |
|                           [MT5](model_doc/mt5)                           |       ✅        |         ✅


key: _node_content
string_value:
{"id_": "c7b2e989-fc0b-4ac4-adfe-09a6a4b6389a", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "98dabb8c-c846-46cb-9bd5-c06d5d77b400", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "3c9268868b6d6528d902f1a275c71d047ad07e2989602f8dc8a90c6f35220413", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "97d339d6-c53b-4e03-b615-5b8982075500", "node_type": "1", "metadata": {}, "hash": "878eafe7e0be5c7e1af989adedbf3c9946baaad2433c15c012acfe9d95519039", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 23529, "end_char_idx": 24447, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
[MPNet](model_doc/mpnet)                         |       ✅        |         ✅         |      ❌      |
|                           [MPT](model_doc/mpt)                           |       ✅        |         ❌         |      ❌      |
|                           [MRA](model_doc/mra)                           |       ✅        |         ❌         |      ❌      |
|                           [MT5](model_doc/mt5)                           |       ✅        |         ✅         |      ✅      |
|                      [MusicGen](model_doc/musicgen)                      |       ✅        |         ❌         |      ❌      |
|               [MusicGen Melody](model_doc/musicgen_melody)               |       ✅        |         ❌         |      ❌      |
|                           [MVP](model_doc/mvp)                           |       ✅        |         ❌         |      ❌      |
|                           [NAT](model_doc/nat)


key: _node_content
string_value:
{"id_": "97d339d6-c53b-4e03-b615-5b8982075500", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "c7b2e989-fc0b-4ac4-adfe-09a6a4b6389a", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "62a9cce389954ac591542ea892bfd5e082a91d06f053214b3ba7f1c7bdbcd8b8", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "d2ed4fcb-7cb7-43fe-9f75-1334bb0988c7", "node_type": "1", "metadata": {}, "hash": "02df87c270888648a339858e489a587a19b57a4b917b8e25ed4d0e000eb259b3", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 23979, "end_char_idx": 24912, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|         ✅         |      ✅      |
|                      [MusicGen](model_doc/musicgen)                      |       ✅        |         ❌         |      ❌      |
|               [MusicGen Melody](model_doc/musicgen_melody)               |       ✅        |         ❌         |      ❌      |
|                           [MVP](model_doc/mvp)                           |       ✅        |         ❌         |      ❌      |
|                           [NAT](model_doc/nat)                           |       ✅        |         ❌         |      ❌      |
|                         [Nezha](model_doc/nezha)                         |       ✅        |         ❌         |      ❌      |
|                          [NLLB](model_doc/nllb)                          |       ✅        |         ❌         |      ❌      |
|                      [NLLB-MOE](model_doc/nllb-moe)                      |       ✅        |         ❌         |      ❌      |
|


key: _node_content
string_value:
{"id_": "d2ed4fcb-7cb7-43fe-9f75-1334bb0988c7", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "97d339d6-c53b-4e03-b615-5b8982075500", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "ec998f432c80713496a23ca772f1bd39a631ec3decd0e23d51621928d66f38fe", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "be04aa82-5847-4170-a499-b1530931929c", "node_type": "1", "metadata": {}, "hash": "ec015772ac15c63f77357545f554e0fe78e11e76952c0032ae91aac1f16cb2ed", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 24474, "end_char_idx": 25398, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ❌         |      ❌      |
|                         [Nezha](model_doc/nezha)                         |       ✅        |         ❌         |      ❌      |
|                          [NLLB](model_doc/nllb)                          |       ✅        |         ❌         |      ❌      |
|                      [NLLB-MOE](model_doc/nllb-moe)                      |       ✅        |         ❌         |      ❌      |
|                        [Nougat](model_doc/nougat)                        |       ✅        |         ✅         |      ✅      |
|                 [Nyströmformer](model_doc/nystromformer)                 |       ✅        |         ❌         |      ❌      |
|                          [OLMo](model_doc/olmo)                          |       ✅        |         ❌         |      ❌      |
|                     [OneFormer](model_doc/oneformer)                     |       ✅        |         ❌


key: _node_content
string_value:
{"id_": "be04aa82-5847-4170-a499-b1530931929c", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "d2ed4fcb-7cb7-43fe-9f75-1334bb0988c7", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "d24b6b2378825ee13f7e326c21190cfe4ae2bee7ac0301c0003bbe0baef4658e", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "5e116c1b-2eb1-4716-9218-af709a66fb53", "node_type": "1", "metadata": {}, "hash": "1260f2284fbe2cdf23cbcf47961d42ef3b5c4f08c8cee7166705ccd28a51b51b", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 24909, "end_char_idx": 25883, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|
|                        [Nougat](model_doc/nougat)                        |       ✅        |         ✅         |      ✅      |
|                 [Nyströmformer](model_doc/nystromformer)                 |       ✅        |         ❌         |      ❌      |
|                          [OLMo](model_doc/olmo)                          |       ✅        |         ❌         |      ❌      |
|                     [OneFormer](model_doc/oneformer)                     |       ✅        |         ❌         |      ❌      |
|                    [OpenAI GPT](model_doc/openai-gpt)                    |       ✅        |         ✅         |      ❌      |
|                      [OpenAI GPT-2](model_doc/gpt2)                      |       ✅        |         ✅         |      ✅      |
|                    [OpenLlama](model_doc/open-llama)                     |       ✅        |         ❌         |      ❌      |
|                           [OPT](model_doc/opt)                           |


key: _node_content
string_value:
{"id_": "5e116c1b-2eb1-4716-9218-af709a66fb53", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "be04aa82-5847-4170-a499-b1530931929c", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "3369af13caa3cd1bb8d5fdea0231180bd28b0f7dbb11f893a2bfc8fe4ee9313b", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "cf1d36e2-5795-4969-83eb-f193e247749d", "node_type": "1", "metadata": {}, "hash": "5ef9596967831b3b696179060fbf304102fb74b33362a0385298d5eb94fbdca9", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 25397, "end_char_idx": 26320, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
❌         |      ❌      |
|                    [OpenAI GPT](model_doc/openai-gpt)                    |       ✅        |         ✅         |      ❌      |
|                      [OpenAI GPT-2](model_doc/gpt2)                      |       ✅        |         ✅         |      ✅      |
|                    [OpenLlama](model_doc/open-llama)                     |       ✅        |         ❌         |      ❌      |
|                           [OPT](model_doc/opt)                           |       ✅        |         ✅         |      ✅      |
|                       [OWL-ViT](model_doc/owlvit)                        |       ✅        |         ❌         |      ❌      |
|                         [OWLv2](model_doc/owlv2)                         |       ✅        |         ❌         |      ❌      |
|                     [PaliGemma](model_doc/paligemma)                     |       ✅        |         ❌         |      ❌      |
|


key: _node_content
string_value:
{"id_": "cf1d36e2-5795-4969-83eb-f193e247749d", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "5e116c1b-2eb1-4716-9218-af709a66fb53", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "77d55529e8f5b7f61082757b3d969da91b9a8f970e016c771881ba2400e1d389", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "7f5b3bc7-5c19-4139-a626-75b1ef3ce6b7", "node_type": "1", "metadata": {}, "hash": "4539d83bc0167d096cad0fe5373db60b0dafb2e0d53392e1e9c375d4c13f5860", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 25882, "end_char_idx": 26816, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|       ✅        |         ✅         |      ✅      |
|                       [OWL-ViT](model_doc/owlvit)                        |       ✅        |         ❌         |      ❌      |
|                         [OWLv2](model_doc/owlv2)                         |       ✅        |         ❌         |      ❌      |
|                     [PaliGemma](model_doc/paligemma)                     |       ✅        |         ❌         |      ❌      |
|                  [PatchTSMixer](model_doc/patchtsmixer)                  |       ✅        |         ❌         |      ❌      |
|                      [PatchTST](model_doc/patchtst)                      |       ✅        |         ❌         |      ❌      |
|                       [Pegasus](model_doc/pegasus)                       |       ✅        |         ✅         |      ✅      |
|                     [PEGASUS-X](model_doc/pegasus_x)                     |       ✅        |         ❌         |


key: _node_content
string_value:
{"id_": "7f5b3bc7-5c19-4139-a626-75b1ef3ce6b7", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "cf1d36e2-5795-4969-83eb-f193e247749d", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "e06aff287a96c912ecf048c82027ebf2d520e50dee1daa93213c44a71056402d", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "f964d786-d1df-4f62-b28e-56f622cbe1ea", "node_type": "1", "metadata": {}, "hash": "b3cd6d923678bddbded590d6c23d80b7b5fa3f2ea4b0141fac25c3b911cda5cb", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 26338, "end_char_idx": 27291, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
[PatchTSMixer](model_doc/patchtsmixer)                  |       ✅        |         ❌         |      ❌      |
|                      [PatchTST](model_doc/patchtst)                      |       ✅        |         ❌         |      ❌      |
|                       [Pegasus](model_doc/pegasus)                       |       ✅        |         ✅         |      ✅      |
|                     [PEGASUS-X](model_doc/pegasus_x)                     |       ✅        |         ❌         |      ❌      |
|                     [Perceiver](model_doc/perceiver)                     |       ✅        |         ❌         |      ❌      |
|                     [Persimmon](model_doc/persimmon)                     |       ✅        |         ❌         |      ❌      |
|                           [Phi](model_doc/phi)                           |       ✅        |         ❌         |      ❌      |
|                          [Phi3](model_doc/phi3)                          |


key: _node_content
string_value:
{"id_": "f964d786-d1df-4f62-b28e-56f622cbe1ea", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "7f5b3bc7-5c19-4139-a626-75b1ef3ce6b7", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "1e5669cf7d16de9b45d1ec5cadb7e3cac212068ec84324bb543fce6db1099925", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "3bed498c-252f-45d4-844d-758325d66447", "node_type": "1", "metadata": {}, "hash": "bf780a405d0fa7b36e52c0e5912981d2c0c21d1f00c46b0bfb2cb2adce0bf7ae", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 26815, "end_char_idx": 27782, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
|      ❌      |
|                     [Perceiver](model_doc/perceiver)                     |       ✅        |         ❌         |      ❌      |
|                     [Persimmon](model_doc/persimmon)                     |       ✅        |         ❌         |      ❌      |
|                           [Phi](model_doc/phi)                           |       ✅        |         ❌         |      ❌      |
|                          [Phi3](model_doc/phi3)                          |       ✅        |         ❌         |      ❌      |
|                       [PhoBERT](model_doc/phobert)                       |       ✅        |         ✅         |      ✅      |
|                    [Pix2Struct](model_doc/pix2struct)                    |       ✅        |         ❌         |      ❌      |
|                        [PLBart](model_doc/plbart)                        |       ✅        |         ❌         |      ❌      |
|                    [PoolFormer](model_doc/poolformer)


key: _node_content
string_value:
{"id_": "3bed498c-252f-45d4-844d-758325d66447", "embedding": null, "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "6be8a835-f94c-4ace-ba6b-6014b9db48e9", "node_type": "4", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "74e62e3b26e0ca81c101a9d08be91c6bea0a2b38629c57fd39d4f9e277eacf7a", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "f964d786-d1df-4f62-b28e-56f622cbe1ea", "node_type": "1", "metadata": {"url": "https://huggingface.co/docs/transformers/index/", "title": "\ud83e\udd17 Transformers", "tokens": 9691, "retrieve_doc": false, "source": "HF_Transformers"}, "hash": "2a7a50bc3cf50c3f6e937429a409c9ecb8658253c12db567acbbdb75c2fc4eea", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "a497d9dd-32d3-4349-b5fb-96a0d229cea0", "node_type": "1", "metadata": {}, "hash": "c968cd66e084ea7bc63323e1541ec58e9ab6be4cc2de724b6dd8aab830de986e", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 27290, "end_char_idx": 28240, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


