Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix package naming #861

Merged
merged 18 commits into from
Jan 22, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import torch
from transformers import AutoTokenizer

from llama_recipes.inference.chat_utils import read_dialogs_from_file
from llama_recipes.inference.model_utils import load_model, load_peft_model
from llama_recipes.inference.safety_utils import get_safety_checker
from llama_cookbook.inference.chat_utils import read_dialogs_from_file
from llama_cookbook.inference.model_utils import load_model, load_peft_model
from llama_cookbook.inference.safety_utils import get_safety_checker
from accelerate.utils import is_xpu_available

def main(
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "llama-cookbook"
version = "0.0.4.post1"
version = "0.0.5"
authors = [
{ name="Hamid Shojanazeri", email="[email protected]" },
{ name="Matthias Reso", email="[email protected]" },
Expand Down Expand Up @@ -36,7 +36,7 @@ exclude = [
]

[tool.hatch.build.targets.wheel]
packages = ["src/llama_recipes"]
packages = ["src/llama_cookbook"]

[tool.hatch.metadata.hooks.requirements_txt]
files = ["requirements.txt"]
Expand Down
3 changes: 0 additions & 3 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ Llama-Cookbook provides a pip distribution for easy install and usage in other p
> Ensure you use the correct CUDA version (from `nvidia-smi`) when installing the PyTorch wheels. Here we are using 11.8 as `cu118`.
> H100 GPUs work better with CUDA >12.0

> > [!NOTE]
When importing, please use the package name `llama_recipes`. We recently renamed the package to `llama-cookbook and will update the library naming in a following release`

#### Install with pip
```
pip install llama-cookbook
Expand Down
22 changes: 11 additions & 11 deletions src/docs/multi_gpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This runs with the `samsum_dataset` for summarization application by default.

```bash

torchrun --nnodes 1 --nproc_per_node 4 recipes/quickstart/finetuning/finetuning.py --enable_fsdp --model_name /path_of_model_folder/8B --use_peft --peft_method lora --output_dir Path/to/save/PEFT/model
torchrun --nnodes 1 --nproc_per_node 4 getting-started/finetuning/finetuning.py --enable_fsdp --model_name /path_of_model_folder/8B --use_peft --peft_method lora --output_dir Path/to/save/PEFT/model

```

Expand All @@ -42,7 +42,7 @@ We use `torchrun` here to spawn multiple processes for FSDP.
Setting `use_fast_kernels` will enable using of Flash Attention or Xformer memory-efficient kernels based on the hardware being used. This would speed up the fine-tuning job. This has been enabled in `optimum` library from HuggingFace as a one-liner API, please read more [here](https://pytorch.org/blog/out-of-the-box-acceleration/).

```bash
torchrun --nnodes 1 --nproc_per_node 4 recipes/quickstart/finetuning/finetuning.py --enable_fsdp --model_name /path_of_model_folder/8B --use_peft --peft_method lora --output_dir Path/to/save/PEFT/model --use_fast_kernels
torchrun --nnodes 1 --nproc_per_node 4 getting-started/finetuning/finetuning.py --enable_fsdp --model_name /path_of_model_folder/8B --use_peft --peft_method lora --output_dir Path/to/save/PEFT/model --use_fast_kernels
```

### Fine-tuning using FSDP Only
Expand All @@ -51,7 +51,7 @@ If interested in running full parameter finetuning without making use of PEFT me

```bash

torchrun --nnodes 1 --nproc_per_node 8 recipes/quickstart/finetuning/finetuning.py --enable_fsdp --model_name /path_of_model_folder/8B --dist_checkpoint_root_folder model_checkpoints --dist_checkpoint_folder fine-tuned --fsdp_config.pure_bf16 --use_fast_kernels
torchrun --nnodes 1 --nproc_per_node 8 getting-started/finetuning/finetuning.py --enable_fsdp --model_name /path_of_model_folder/8B --dist_checkpoint_root_folder model_checkpoints --dist_checkpoint_folder fine-tuned --fsdp_config.pure_bf16 --use_fast_kernels

```

Expand All @@ -69,7 +69,7 @@ If you are interested in running full parameter fine-tuning on the 70B model, yo

```bash

torchrun --nnodes 1 --nproc_per_node 8 recipes/quickstart/finetuning/finetuning.py --enable_fsdp --low_cpu_fsdp --fsdp_config.pure_bf16 --model_name /path_of_model_folder/70B --batch_size_training 1 --dist_checkpoint_root_folder model_checkpoints --dist_checkpoint_folder fine-tuned
torchrun --nnodes 1 --nproc_per_node 8 getting-started/finetuning/finetuning.py --enable_fsdp --low_cpu_fsdp --fsdp_config.pure_bf16 --model_name /path_of_model_folder/70B --batch_size_training 1 --dist_checkpoint_root_folder model_checkpoints --dist_checkpoint_folder fine-tuned

```

Expand All @@ -79,7 +79,7 @@ Here we use a slurm script to schedule a job with slurm over multiple nodes.

```bash

sbatch recipes/quickstart/finetuning/multi_node.slurm
sbatch getting-started/finetuning/multi_node.slurm
# Change the num nodes and GPU per nodes in the script before running.

```
Expand All @@ -102,16 +102,16 @@ To run with each of the datasets set the `dataset` flag in the command as shown

```bash
# grammer_dataset
torchrun --nnodes 1 --nproc_per_node 4 recipes/quickstart/finetuning/finetuning.py --enable_fsdp --model_name /path_of_model_folder/8B --use_peft --peft_method lora --dataset grammar_dataset --save_model --dist_checkpoint_root_folder model_checkpoints --dist_checkpoint_folder fine-tuned --fsdp_config.pure_bf16 --output_dir Path/to/save/PEFT/model
torchrun --nnodes 1 --nproc_per_node 4 getting-started/finetuning/finetuning.py --enable_fsdp --model_name /path_of_model_folder/8B --use_peft --peft_method lora --dataset grammar_dataset --save_model --dist_checkpoint_root_folder model_checkpoints --dist_checkpoint_folder fine-tuned --fsdp_config.pure_bf16 --output_dir Path/to/save/PEFT/model

# alpaca_dataset

torchrun --nnodes 1 --nproc_per_node 4 recipes/quickstart/finetuning/finetuning.py --enable_fsdp --model_name /path_of_model_folder/8B --use_peft --peft_method lora --dataset alpaca_dataset --save_model --dist_checkpoint_root_folder model_checkpoints --dist_checkpoint_folder fine-tuned --fsdp_config.pure_bf16 --output_dir Path/to/save/PEFT/model
torchrun --nnodes 1 --nproc_per_node 4 getting-started/finetuning/finetuning.py --enable_fsdp --model_name /path_of_model_folder/8B --use_peft --peft_method lora --dataset alpaca_dataset --save_model --dist_checkpoint_root_folder model_checkpoints --dist_checkpoint_folder fine-tuned --fsdp_config.pure_bf16 --output_dir Path/to/save/PEFT/model


# samsum_dataset

torchrun --nnodes 1 --nproc_per_node 4 recipes/quickstart/finetuning/finetuning.py --enable_fsdp --model_name /path_of_model_folder/8B --use_peft --peft_method lora --dataset samsum_dataset --save_model --dist_checkpoint_root_folder model_checkpoints --dist_checkpoint_folder fine-tuned --fsdp_config.pure_bf16 --output_dir Path/to/save/PEFT/model
torchrun --nnodes 1 --nproc_per_node 4 getting-started/finetuning/finetuning.py --enable_fsdp --model_name /path_of_model_folder/8B --use_peft --peft_method lora --dataset samsum_dataset --save_model --dist_checkpoint_root_folder model_checkpoints --dist_checkpoint_folder fine-tuned --fsdp_config.pure_bf16 --output_dir Path/to/save/PEFT/model

```

Expand Down Expand Up @@ -166,11 +166,11 @@ It lets us specify the training settings for everything from `model_name` to `da
profiler_dir: str = "PATH/to/save/profiler/results" # will be used if using profiler
```

* [Datasets config file](../llama_recipes/configs/datasets.py) provides the available options for datasets.
* [Datasets config file](../llama_cookbook/configs/datasets.py) provides the available options for datasets.

* [peft config file](../llama_recipes/configs/peft.py) provides the supported PEFT methods and respective settings that can be modified.
* [peft config file](../llama_cookbook/configs/peft.py) provides the supported PEFT methods and respective settings that can be modified.

* [FSDP config file](../llama_recipes/configs/fsdp.py) provides FSDP settings such as:
* [FSDP config file](../llama_cookbook/configs/fsdp.py) provides FSDP settings such as:

* `mixed_precision` boolean flag to specify using mixed precision, defatults to true.

Expand Down
10 changes: 5 additions & 5 deletions src/docs/single_gpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Get access to a machine with one GPU or if using a multi-GPU machine please make

```bash

python -m llama_recipes.finetuning --use_peft --peft_method lora --quantization 8bit --use_fp16 --model_name /path_of_model_folder/8B --output_dir Path/to/save/PEFT/model
python -m llama_cookbook.finetuning --use_peft --peft_method lora --quantization 8bit --use_fp16 --model_name /path_of_model_folder/8B --output_dir Path/to/save/PEFT/model

```
The args used in the command above are:
Expand All @@ -42,7 +42,7 @@ Currently 4 datasets are supported that can be found in [Datasets config file](.
* `alpaca_dataset` : to get this open source data please download the `aplaca.json` to `ft_dataset` folder.

```bash
wget -P src/llama_recipes/datasets https://raw.githubusercontent.com/tatsu-lab/stanford_alpaca/main/alpaca_data.json
wget -P src/llama_cookbook/datasets https://raw.githubusercontent.com/tatsu-lab/stanford_alpaca/main/alpaca_data.json
```

* `samsum_dataset`
Expand All @@ -52,16 +52,16 @@ to run with each of the datasets set the `dataset` flag in the command as shown
```bash
# grammer_dataset

python -m llama_recipes.finetuning --use_peft --peft_method lora --quantization 8bit --dataset grammar_dataset --model_name /path_of_model_folder/8B --output_dir Path/to/save/PEFT/model
python -m llama_cookbook.finetuning --use_peft --peft_method lora --quantization 8bit --dataset grammar_dataset --model_name /path_of_model_folder/8B --output_dir Path/to/save/PEFT/model

# alpaca_dataset

python -m llama_recipes.finetuning --use_peft --peft_method lora --quantization 8bit --dataset alpaca_dataset --model_name /path_of_model_folder/8B --output_dir Path/to/save/PEFT/model
python -m llama_cookbook.finetuning --use_peft --peft_method lora --quantization 8bit --dataset alpaca_dataset --model_name /path_of_model_folder/8B --output_dir Path/to/save/PEFT/model


# samsum_dataset

python -m llama_recipes.finetuning --use_peft --peft_method lora --quantization 8bit --dataset samsum_dataset --model_name /path_of_model_folder/8B --output_dir Path/to/save/PEFT/model
python -m llama_cookbook.finetuning --use_peft --peft_method lora --quantization 8bit --dataset samsum_dataset --model_name /path_of_model_folder/8B --output_dir Path/to/save/PEFT/model

```

Expand Down
8 changes: 8 additions & 0 deletions src/llama_cookbook/configs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.

from llama_cookbook.configs.peft import lora_config, llama_adapter_config, prefix_config
from llama_cookbook.configs.fsdp import fsdp_config
from llama_cookbook.configs.training import train_config
from llama_cookbook.configs.wandb import wandb_config
from llama_cookbook.configs.quantization import quantization_config
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

from functools import partial

from llama_recipes.datasets.grammar_dataset.grammar_dataset import get_dataset as get_grammar_dataset
from llama_recipes.datasets.alpaca_dataset import InstructionDataset as get_alpaca_dataset
from llama_recipes.datasets.custom_dataset import get_custom_dataset,get_data_collator
from llama_recipes.datasets.samsum_dataset import get_preprocessed_samsum as get_samsum_dataset
from llama_recipes.datasets.toxicchat_dataset import get_llamaguard_toxicchat_dataset as get_llamaguard_toxicchat_dataset
from llama_cookbook.datasets.grammar_dataset.grammar_dataset import get_dataset as get_grammar_dataset
from llama_cookbook.datasets.alpaca_dataset import InstructionDataset as get_alpaca_dataset
from llama_cookbook.datasets.custom_dataset import get_custom_dataset,get_data_collator
from llama_cookbook.datasets.samsum_dataset import get_preprocessed_samsum as get_samsum_dataset
from llama_cookbook.datasets.toxicchat_dataset import get_llamaguard_toxicchat_dataset as get_llamaguard_toxicchat_dataset
DATASET_PREPROC = {
"alpaca_dataset": partial(get_alpaca_dataset),
"grammar_dataset": get_grammar_dataset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import copy
import datasets
import itertools
from llama_recipes.inference.prompt_format_utils import LLAMA_GUARD_3_CATEGORY
from llama_cookbook.inference.prompt_format_utils import LLAMA_GUARD_3_CATEGORY
import ast
import fire

Expand All @@ -19,7 +19,7 @@ def tokenize_prompt_and_labels(full_prompt, tokenizer):
return dict(combined_tokens, attention_mask=[1]*len(combined_tokens["input_ids"]))


from llama_recipes.data.llama_guard.finetuning_data_formatter import TrainingExample, Guidelines, Category, LlamaGuardPromptConfigs, LlamaGuardGenerationConfigs, ExplanationPosition, AugmentationConfigs, FormatterConfigs, create_formatted_finetuning_examples
from llama_cookbook.data.llama_guard.finetuning_data_formatter import TrainingExample, Guidelines, Category, LlamaGuardPromptConfigs, LlamaGuardGenerationConfigs, ExplanationPosition, AugmentationConfigs, FormatterConfigs, create_formatted_finetuning_examples
from datasets import Dataset, DatasetInfo

def mapTcCategoriesToLGCategories(TcCategoriesString):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@
import torch.optim as optim
from accelerate.utils import is_xpu_available

from llama_recipes.configs import (
from llama_cookbook.configs import (
fsdp_config as FSDP_CONFIG,
quantization_config as QUANTIZATION_CONFIG,
train_config as TRAIN_CONFIG,
)
from llama_recipes.data.concatenator import ConcatDataset
from llama_recipes.policies import AnyPrecisionAdamW, apply_fsdp_checkpointing
from llama_cookbook.data.concatenator import ConcatDataset
from llama_cookbook.policies import AnyPrecisionAdamW, apply_fsdp_checkpointing

from llama_recipes.utils import fsdp_auto_wrap_policy
from llama_recipes.utils.config_utils import (
from llama_cookbook.utils import fsdp_auto_wrap_policy
from llama_cookbook.utils.config_utils import (
check_fsdp_config,
generate_dataset_config,
generate_peft_config,
get_dataloader_kwargs,
update_config,
)
from llama_recipes.utils.dataset_utils import (
from llama_cookbook.utils.dataset_utils import (
get_custom_data_collator,
get_preprocessed_dataset,
)

from llama_recipes.utils.fsdp_utils import hsdp_device_mesh
from llama_recipes.utils.train_utils import (
from llama_cookbook.utils.fsdp_utils import hsdp_device_mesh
from llama_cookbook.utils.train_utils import (
clear_gpu_cache,
freeze_transformer_layers,
freeze_LLM_only,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import fire
import yaml

from llama_recipes.inference.model_utils import load_llama_from_config
from llama_cookbook.inference.model_utils import load_llama_from_config

from transformers import AutoConfig, AutoTokenizer, MllamaProcessor

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from warnings import warn

from llama_recipes.configs import quantization_config as QUANT_CONFIG
from llama_recipes.utils.config_utils import update_config
from llama_cookbook.configs import quantization_config as QUANT_CONFIG
from llama_cookbook.utils.config_utils import update_config
from peft import PeftModel
from transformers import (
AutoConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.

from llama_recipes.model_checkpointing.checkpoint_handler import (
from llama_cookbook.model_checkpointing.checkpoint_handler import (
load_model_checkpoint,
save_fsdp_model_checkpoint_full,
save_peft_checkpoint,
Expand Down
7 changes: 7 additions & 0 deletions src/llama_cookbook/policies/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.

from llama_cookbook.policies.mixed_precision import *
from llama_cookbook.policies.wrapping import *
from llama_cookbook.policies.activation_checkpointing_functions import apply_fsdp_checkpointing
from llama_cookbook.policies.anyprecision_optimizer import AnyPrecisionAdamW
File renamed without changes.
7 changes: 7 additions & 0 deletions src/llama_cookbook/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.

from llama_cookbook.utils.memory_utils import MemoryTrace
from llama_cookbook.utils.dataset_utils import *
from llama_cookbook.utils.fsdp_utils import fsdp_auto_wrap_policy, hsdp_device_mesh
from llama_cookbook.utils.train_utils import *
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from transformers import default_data_collator
from transformers.data import DataCollatorForSeq2Seq

from llama_recipes.configs import datasets, lora_config, llama_adapter_config, prefix_config, train_config
from llama_recipes.data.sampler import LengthBasedBatchSampler, DistributedLengthBasedBatchSampler
from llama_recipes.datasets import DATASET_PREPROC
from llama_cookbook.configs import datasets, lora_config, llama_adapter_config, prefix_config, train_config
from llama_cookbook.data.sampler import LengthBasedBatchSampler, DistributedLengthBasedBatchSampler
from llama_cookbook.datasets import DATASET_PREPROC

def update_config(config, **kwargs):
if isinstance(config, (tuple, list)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import torch

from llama_recipes.data.concatenator import ConcatDataset
from llama_recipes.datasets import DATASET_PREPROC, DATALOADER_COLLATE_FUNC
from llama_recipes.utils.config_utils import get_dataloader_kwargs
from llama_cookbook.data.concatenator import ConcatDataset
from llama_cookbook.datasets import DATASET_PREPROC, DATALOADER_COLLATE_FUNC
from llama_cookbook.utils.config_utils import get_dataloader_kwargs


def get_preprocessed_dataset(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import json


from llama_recipes.model_checkpointing import save_fsdp_model_checkpoint_full, save_model_and_optimizer_sharded, save_optimizer_checkpoint, save_peft_checkpoint, save_model_checkpoint
from llama_recipes.policies import fpSixteen,bfSixteen, get_llama_wrapper
from llama_recipes.utils.memory_utils import MemoryTrace
from llama_cookbook.model_checkpointing import save_fsdp_model_checkpoint_full, save_model_and_optimizer_sharded, save_optimizer_checkpoint, save_peft_checkpoint, save_model_checkpoint
from llama_cookbook.policies import fpSixteen,bfSixteen, get_llama_wrapper
from llama_cookbook.utils.memory_utils import MemoryTrace
from accelerate.utils import is_xpu_available, is_ccl_available
from llama_recipes.utils.flop_utils import FlopMeasure
from llama_cookbook.utils.flop_utils import FlopMeasure
def set_tokenizer_params(tokenizer: LlamaTokenizer):
tokenizer.pad_token_id = 0
tokenizer.padding_side = "left"
Expand Down
8 changes: 0 additions & 8 deletions src/llama_recipes/configs/__init__.py

This file was deleted.

7 changes: 0 additions & 7 deletions src/llama_recipes/policies/__init__.py

This file was deleted.

7 changes: 0 additions & 7 deletions src/llama_recipes/utils/__init__.py

This file was deleted.

Loading