Skip to content

Commit

Permalink
Tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
carmocca committed Mar 7, 2024
1 parent e94ca9e commit 9a4d7f7
Show file tree
Hide file tree
Showing 23 changed files with 54 additions and 57 deletions.
2 changes: 1 addition & 1 deletion litgpt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def check_valid_checkpoint_dir(checkpoint_dir: Path) -> None:
error_message = (
f"--checkpoint_dir {str(checkpoint_dir.absolute())!r}{problem}."
"\nFind download instructions at https://github.com/Lightning-AI/litgpt/blob/main/tutorials\n"
f"{extra}\nSee all download options by running:\n python scripts/download.py"
f"{extra}\nSee all download options by running:\n python litgpt/scripts/download.py"
)
print(error_message, file=sys.stderr)
raise SystemExit(1)
Expand Down
2 changes: 1 addition & 1 deletion notebooks/falcon-inference.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"outputs": [],
"source": [
"# download the weights\n",
"!python scripts/download.py --repo_id tiiuae/falcon-7b"
"!python litgpt/scripts/download.py --repo_id tiiuae/falcon-7b"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_check_valid_checkpoint_dir(tmp_path):
Find download instructions at https://github.com/Lightning-AI/litgpt/blob/main/tutorials
See all download options by running:
python scripts/download.py
python litgpt/scripts/download.py
""".strip()
assert out == expected

Expand All @@ -57,7 +57,7 @@ def test_check_valid_checkpoint_dir(tmp_path):
Find download instructions at https://github.com/Lightning-AI/litgpt/blob/main/tutorials
See all download options by running:
python scripts/download.py
python litgpt/scripts/download.py
""".strip()
assert out == expected

Expand All @@ -75,7 +75,7 @@ def test_check_valid_checkpoint_dir(tmp_path):
--checkpoint_dir '{str(checkpoint_dir.absolute())}'
See all download options by running:
python scripts/download.py
python litgpt/scripts/download.py
""".strip()
assert out == expected

Expand Down
12 changes: 6 additions & 6 deletions tutorials/convert_hf_checkpoint.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Converting Hugging Face Transformers to LitGPT weights

By default, the `scripts/download.py` script converts the downloaded HF checkpoint files into a LitGPT compatible format after downloading. For example,
By default, the `litgpt/scripts/download.py` script converts the downloaded HF checkpoint files into a LitGPT compatible format after downloading. For example,

```bash
python scripts/download.py --repo_id EleutherAI/pythia-14m
python litgpt/scripts/download.py --repo_id EleutherAI/pythia-14m
```

creates the following files:
Expand All @@ -23,12 +23,12 @@ checkpoints/



To disable the automatic conversion, which is useful for development and debugging purposes, you can run the `scripts/download.py` with the `--convert_checkpoint false` flag. This will only download the checkpoint files but do not convert them for use in LitGPT:
To disable the automatic conversion, which is useful for development and debugging purposes, you can run the `litgpt/scripts/download.py` with the `--convert_checkpoint false` flag. This will only download the checkpoint files but do not convert them for use in LitGPT:

```bash
rm -rf checkpoints/EleutherAI/pythia-14m

python scripts/download.py \
python litgpt/scripts/download.py \
--repo_id EleutherAI/pythia-14m \
--convert_checkpoint false

Expand All @@ -46,10 +46,10 @@ ls checkpoints/EleutherAI/pythia-14m
└── tokenizer_config.json
```

The required files `lit_config.json` and `lit_model.pth` files can then be manually generated via the `scripts/convert_hf_checkpoint.py` script:
The required files `lit_config.json` and `lit_model.pth` files can then be manually generated via the `litgpt/scripts/convert_hf_checkpoint.py` script:

```bash
python scripts/convert_hf_checkpoint.py \
python litgpt/scripts/convert_hf_checkpoint.py \
--checkpoint_dir checkpoints/EleutherAI/pythia-14m
```

8 changes: 4 additions & 4 deletions tutorials/convert_lit_models.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LitGPT weights need to be converted to a format that Hugging Face understands wi
We provide a helpful script to convert models LitGPT models back to their equivalent Hugging Face Transformers format:

```sh
python scripts/convert_lit_checkpoint.py \
python litgpt/scripts/convert_lit_checkpoint.py \
--checkpoint_path checkpoints/repo_id/lit_model.pth \
--output_path output_path/converted.pth \
--config_path checkpoints/repo_id/config.json
Expand Down Expand Up @@ -70,12 +70,12 @@ export repo_id=TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T

Instead of using TinyLlama, you can replace the `repo_id` target with any other model repository
specifier that is currently supported by LitGPT. You can get a list of supported repository specifier
by running `scripts/download.py` without any additional arguments.
by running `litgpt/scripts/download.py` without any additional arguments.

Then, we download the model we specified via `$repo_id` above:

```bash
python scripts/download.py --repo_id $repo_id
python litgpt/scripts/download.py --repo_id $repo_id
```


Expand Down Expand Up @@ -113,7 +113,7 @@ python scripts/merge_lora.py \
5. Convert the finetuning model back into a HF format:

```bash
python scripts/convert_lit_checkpoint.py \
python litgpt/scripts/convert_lit_checkpoint.py \
--checkpoint_path $finetuned_dir/final/lit_model.pth \
--output_path out/hf-tinyllama/converted_model.pth \
--config_path checkpoints/$repo_id/lit_config.json
Expand Down
4 changes: 2 additions & 2 deletions tutorials/download_code_llama.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ All models were trained on 16,000 token contexts and support generations with u
To see all the available checkpoints, run:

```bash
python scripts/download.py | grep CodeLlama
python litgpt/scripts/download.py | grep CodeLlama
```

which will print
Expand All @@ -38,7 +38,7 @@ In order to use a specific checkpoint, for instance [CodeLlama-7b-Python-hf](htt
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id codellama/CodeLlama-7b-Python-hf
python litgpt/scripts/download.py --repo_id codellama/CodeLlama-7b-Python-hf
```

By default, the checkpoint conversion step will use the data type of the HF checkpoint's parameters. In cases where RAM
Expand Down
4 changes: 2 additions & 2 deletions tutorials/download_dolly.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ For detailed info on the models, their training, and their behavior, please see
To see all the available checkpoints for Dolly, run:

```bash
python scripts/download.py | grep dolly
python litgpt/scripts/download.py | grep dolly
```

which will print
Expand All @@ -28,7 +28,7 @@ In order to use a specific Dolly checkpoint, for instance [dolly-v2-3b](https://
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id databricks/dolly-v2-3b
python litgpt/scripts/download.py --repo_id databricks/dolly-v2-3b
```

By default, the checkpoint conversion step will use the data type of the HF checkpoint's parameters. In cases where RAM
Expand Down
4 changes: 2 additions & 2 deletions tutorials/download_falcon.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The first Falcon release includes a base model and an instruction tuned model of
To see all the available checkpoints for Falcon, run:

```bash
python scripts/download.py | grep falcon
python litgpt/scripts/download.py | grep falcon
```

which will print
Expand All @@ -28,7 +28,7 @@ In order to use a specific Falcon checkpoint, for instance [falcon-7b](https://h
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id tiiuae/falcon-7b
python litgpt/scripts/download.py --repo_id tiiuae/falcon-7b
```

By default, the checkpoint conversion step will use the data type of the HF checkpoint's parameters. In cases where RAM
Expand Down
2 changes: 1 addition & 1 deletion tutorials/download_freewilly_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ FreeWilly2 leverages the Llama 2 70B foundation model to reach a performance tha
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id stabilityai/FreeWilly2
python litgpt/scripts/download.py --repo_id stabilityai/FreeWilly2
```

By default, the checkpoint conversion step will use the data type of the HF checkpoint's parameters. In cases where RAM
Expand Down
2 changes: 1 addition & 1 deletion tutorials/download_function_calling_llama_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ In order to use the checkpoint, download the weights and convert the checkpoint
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id Trelis/Llama-2-7b-chat-hf-function-calling-v2
python litgpt/scripts/download.py --repo_id Trelis/Llama-2-7b-chat-hf-function-calling-v2
```

By default, the checkpoint conversion step will use the data type of the HF checkpoint's parameters. In cases where RAM
Expand Down
4 changes: 2 additions & 2 deletions tutorials/download_gemma.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For more information, please see the [technical report](https://storage.googleap
To see all the available checkpoints, run:

```bash
python scripts/download.py | grep gemma
python litgpt/scripts/download.py | grep gemma
```

which will print
Expand All @@ -30,7 +30,7 @@ After access is granted, you can find your HF hub token in <https://huggingface.
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id google/gemma-2b --access_token your_hf_token
python litgpt/scripts/download.py --repo_id google/gemma-2b --access_token your_hf_token
```

By default, the checkpoint conversion step will use the data type of the HF checkpoint's parameters. In cases where RAM
Expand Down
4 changes: 2 additions & 2 deletions tutorials/download_llama_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Llama 2 comes in a range of parameter sizes — 7B, 13B, and 70B — as well as
To see all the available checkpoints, run:

```bash
python scripts/download.py | grep Llama-2
python litgpt/scripts/download.py | grep Llama-2
```

which will print
Expand All @@ -35,7 +35,7 @@ After access is granted, you can find your HF hub token in <https://huggingface.
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id meta-llama/Llama-2-7b-chat-hf --access_token your_hf_token
python litgpt/scripts/download.py --repo_id meta-llama/Llama-2-7b-chat-hf --access_token your_hf_token
```

By default, the checkpoint conversion step will use the data type of the HF checkpoint's parameters. In cases where RAM
Expand Down
4 changes: 2 additions & 2 deletions tutorials/download_longchat.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The technique used to extend the context length is described in [this blogpost](
To see all the available checkpoints, run:

```bash
python scripts/download.py | grep longchat
python litgpt/scripts/download.py | grep longchat
```

which will print
Expand All @@ -21,7 +21,7 @@ In order to use a specific checkpoint, for instance [longchat-7b-16k](https://hu
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id lmsys/longchat-7b-16k
python litgpt/scripts/download.py --repo_id lmsys/longchat-7b-16k
```

By default, the checkpoint conversion step will use the data type of the HF checkpoint's parameters. In cases where RAM
Expand Down
6 changes: 3 additions & 3 deletions tutorials/download_mistral.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Details about the data used to train the model or training procedure have not be
To see all the available checkpoints, run:

```bash
python scripts/download.py | grep -E 'Mistral|Mixtral'
python litgpt/scripts/download.py | grep -E 'Mistral|Mixtral'
```

which will print
Expand All @@ -34,7 +34,7 @@ In order to use the Mistral 7B model checkpoint, which requires about 14 GB of d
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id mistralai/Mistral-7B-Instruct-v0.2
python litgpt/scripts/download.py --repo_id mistralai/Mistral-7B-Instruct-v0.2
```

You're done! To execute the model just run:
Expand All @@ -57,7 +57,7 @@ In order to use the Mixtral 7B model checkpoint, which requires about 94 GB of d
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id mistralai/Mixtral-8x7B-Instruct-v0.1
python litgpt/scripts/download.py --repo_id mistralai/Mixtral-8x7B-Instruct-v0.1
```

Due to the size of the model, currently only the multi-device sequential generation script can handle it.
Expand Down
6 changes: 2 additions & 4 deletions tutorials/download_openllama.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The weights can serve as the drop in replacement of LLaMA in existing implementa
To see all the available checkpoints for Open LLaMA, run:

```bash
python scripts/download.py | grep open_llama
python litgpt/scripts/download.py | grep open_llama
```

which will print
Expand All @@ -23,9 +23,7 @@ In order to use a specific OpenLLaMA checkpoint, for instance [open_llama_3b](ht
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id openlm-research/open_llama_3b

python scripts/convert_hf_checkpoint.py --checkpoint_dir checkpoints/openlm-research/open_llama_3b
python litgpt/scripts/download.py --repo_id openlm-research/open_llama_3b
```

By default, the convert_hf_checkpoint step will use the data type of the HF checkpoint's parameters. In cases where RAM
Expand Down
4 changes: 2 additions & 2 deletions tutorials/download_phi.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To download the model weights and convert them to the litgpt format, run
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id microsoft/phi-2
python litgpt/scripts/download.py --repo_id microsoft/phi-2
```

> [!WARNING]
Expand Down Expand Up @@ -61,7 +61,7 @@ In order to use the phi-1.5 model checkpoint, which requires about 3 Gb of disk
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id microsoft/phi-1_5
python litgpt/scripts/download.py --repo_id microsoft/phi-1_5
```

You're done! To execute the model just run:
Expand Down
4 changes: 2 additions & 2 deletions tutorials/download_pythia.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ It includes a suite of 8 checkpoints (weights) on 2 different datasets: [The Pil
To see all the available checkpoints for Pythia, run:

```bash
python scripts/download.py | grep pythia
python litgpt/scripts/download.py | grep pythia
```

which will print
Expand Down Expand Up @@ -39,7 +39,7 @@ In order to use a specific Pythia checkpoint, for instance [pythia-1b](https://h
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id EleutherAI/pythia-1b
python litgpt/scripts/download.py --repo_id EleutherAI/pythia-1b
```

By default, the checkpoint conversion step will use the data type of the HF checkpoint's parameters. In cases where RAM
Expand Down
4 changes: 2 additions & 2 deletions tutorials/download_redpajama_incite.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The release includes a base model, a chat fine-tuned model, and an instruction t
To see all the available checkpoints for RedPajama-INCITE, run:

```bash
python scripts/download.py | grep RedPajama
python litgpt/scripts/download.py | grep RedPajama
```

which will print
Expand All @@ -29,7 +29,7 @@ In order to use a specific RedPajama-INCITE checkpoint, for instance [RedPajama-
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id togethercomputer/RedPajama-INCITE-Base-3B-v1
python litgpt/scripts/download.py --repo_id togethercomputer/RedPajama-INCITE-Base-3B-v1
```

By default, the checkpoint conversion step will use the data type of the HF checkpoint's parameters. In cases where RAM
Expand Down
4 changes: 2 additions & 2 deletions tutorials/download_stablecode.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ For more info on the models, please visit the [StableCode repository](https://hu
To see all the available checkpoints for StableCode, run:

```bash
python scripts/download.py | grep -E "stable-?code"
python litgpt/scripts/download.py | grep -E "stable-?code"
```

which will print:
Expand All @@ -29,7 +29,7 @@ In order to use a specific StableCode checkpoint, for instance [stable-code-3b](
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

export repo_id=stabilityai/stable-code-3b
python scripts/download.py --repo_id $repo_id
python litgpt/scripts/download.py --repo_id $repo_id
```

By default, the checkpoint conversion step will use the data type of the HF checkpoint's parameters. In cases where RAM
Expand Down
7 changes: 3 additions & 4 deletions tutorials/download_stablelm.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ StableLM is a family of generative language models trained by StabilityAI.
To see all the available checkpoints for StableLM, run:

```bash
python scripts/download.py | grep stablelm
python litgpt/scripts/download.py | grep stablelm
```

which will print:
Expand All @@ -24,7 +24,7 @@ In order to use a specific StableLM checkpoint, for instance [stablelm-base-alph
```bash
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

python scripts/download.py --repo_id stabilityai/stablelm-base-alpha-3b
python litgpt/scripts/download.py --repo_id stabilityai/stablelm-base-alpha-3b
```

By default, the checkpoint conversion step will use the data type of the HF checkpoint's parameters. In cases where RAM
Expand Down Expand Up @@ -56,8 +56,7 @@ In order to use a specific StableLM checkpoint, for instance [StableLM Zephyr 3B
pip install 'huggingface_hub[hf_transfer] @ git+https://github.com/huggingface/huggingface_hub'

export repo_id=stabilityai/stablelm-zephyr-3b
python scripts/download.py --repo_id $repo_id
python scripts/convert_hf_checkpoint.py --checkpoint_dir checkpoints/$repo_id
python litgpt/scripts/download.py --repo_id $repo_id
```

By default, the `convert_hf_checkpoint` step will use the data type of the HF checkpoint's parameters. In cases where RAM
Expand Down
Loading

0 comments on commit 9a4d7f7

Please sign in to comment.