Skip to content

Commit aee2c84

Browse files
authored
Clarify llm download/loading instructions (apache#25145)
* Clarify llm download/loading instructions * Fix instructions * Default model name * Install beam * Provide some extra info on LLM
1 parent 16cb63b commit aee2c84

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

sdks/python/apache_beam/examples/inference/large_language_modeling/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ def parse_args(argv):
8888
parser.add_argument(
8989
"--model_name",
9090
dest="model_name",
91-
required=True,
91+
required=False,
9292
help="Path to the model's state_dict.",
93-
default="t5-small",
93+
default="t5-11b",
9494
)
9595

9696
return parser.parse_known_args(args=argv)

website/www/site/content/en/documentation/ml/large-language-modeling.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,31 @@ RunInference works well on arbitrarily large models as long as they can fit on y
2525
This example demonstrates running inference with a `T5` language model using `RunInference` in a pipeline. `T5` is an encoder-decoder model pre-trained on a multi-task mixture of unsupervised and supervised tasks. Each task is converted into a text-to-text format. The example uses `T5-11B`, which contains 11 billion parameters and is 45 GB in size. In order to work well on a variety of tasks, `T5` prepends a different prefix to the input corresponding to each task. For example, for translation, the input would be: `translate English to German: …` and for summarization, it would be: `summarize: …`. For more information about `T5` see the [T5 overiew](https://huggingface.co/docs/transformers/model_doc/t5) in the HuggingFace documentation.
2626

2727
### Run the Pipeline ?
28-
First, install the required packages listed in [requirements.txt](https://github.com/apache/beam/blob/master/sdks/python/apache_beam/examples/inference/large_language_modeling/requirements.txt) and pass the required arguments. You can download the `T5-11b` model from [Hugging Face Hub](https://huggingface.co/t5-11b) using:
28+
First, install `apache-beam` 2.40 or greater:
2929

30-
- git lfs install
31-
- git clone https://huggingface.co/t5-11b
32-
Note: It will download the checkpoint, then you need to convert it to the model state dict as mentioned [here](https://pytorch.org/tutorials/beginner/saving_loading_models.html#save-load-state-dict-recommended).
30+
```
31+
pip install apache-beam -U
32+
```
33+
34+
Next, install the required packages listed in [requirements.txt](https://github.com/apache/beam/blob/master/sdks/python/apache_beam/examples/inference/large_language_modeling/requirements.txt) and pass the required arguments. You can download the `T5-11b` model from [Hugging Face Hub](https://huggingface.co/t5-11b) with the following steps:
35+
36+
- Install Git LFS following the instructions [here](https://docs.github.com/en/repositories/working-with-files/managing-large-files/installing-git-large-file-storage?platform=mac)
37+
- Run `git lfs install`
38+
- Run `git clone https://huggingface.co/t5-11b` (this may take a long time). This will download the checkpoint, then you need to convert it to the model state dict as described [here](https://pytorch.org/tutorials/beginner/saving_loading_models.html#save-load-state-dict-recommended):
39+
40+
```
41+
import torch
42+
from transformers import T5ForConditionalGeneration
43+
44+
model = T5ForConditionalGeneration.from_pretrained("path/to/cloned/t5-11b")
45+
torch.save(model.state_dict(), "path/to/save/state_dict.pth")
46+
```
3347

3448
You can view the code on [GitHub](https://github.com/apache/beam/tree/master/sdks/python/apache_beam/examples/inference/large_language_modeling/main.py)
3549

3650
1. Locally on your machine: `python main.py --runner DirectRunner --model_state_dict_path <local or remote path to state_dict>`. You need to have 45 GB of disk space available to run this example.
37-
2. On Google Cloud using Dataflow: `python main.py --runner DataflowRunner --model_state_dict_path <local or remote path to state_dict> --project PROJECT_ID
38-
--region REGION --requirements_file requirements.txt --temp_location GCS_PATH`. Make sure to pass other arguments as mentioned [here](https://cloud.google.com/dataflow/docs/guides/setting-pipeline-options#setting_required_options)
51+
2. On Google Cloud using Dataflow: `python main.py --runner DataflowRunner --model_state_dict_path <gs://path/to/saved/state_dict.pth> --project <PROJECT_ID>
52+
--region <REGION> --requirements_file requirements.txt --temp_location <gs://path/to/temp/location> --experiments "use_runner_v2,no_use_multiple_sdk_containers" --machine_type=n2-standard-16`. You can also pass other configuration parameters as described [here](https://cloud.google.com/dataflow/docs/guides/setting-pipeline-options#setting_required_options).
3953

4054
### Pipeline Steps
4155
The pipeline contains the following steps:

0 commit comments

Comments
 (0)