فهرست منبع

Fix package naming (#861)

Sanyam Bhutani 3 ماه پیش
والد
کامیت
69b9ca106f
72فایلهای تغییر یافته به همراه229 افزوده شده و 232 حذف شده
  1. 1 1
      getting-started/README.md
  2. 7 7
      getting-started/finetuning/README.md
  3. 14 14
      getting-started/finetuning/datasets/README.md
  4. 6 6
      getting-started/finetuning/multigpu_finetuning.md
  5. 5 5
      getting-started/finetuning/singlegpu_finetuning.md
  6. 3 3
      getting-started/inference/local_inference/README.md
  7. 3 3
      getting-started/inference/local_inference/chat_completion/chat_completion.py
  8. 2 2
      pyproject.toml
  9. 0 3
      src/README.md
  10. 2 2
      src/docs/FAQ.md
  11. 16 16
      src/docs/multi_gpu.md
  12. 11 11
      src/docs/single_gpu.md
  13. 8 0
      src/llama_cookbook/configs/__init__.py
  14. 0 0
      src/llama_cookbook/configs/datasets.py
  15. 0 0
      src/llama_cookbook/configs/fsdp.py
  16. 0 0
      src/llama_cookbook/configs/peft.py
  17. 0 0
      src/llama_cookbook/configs/quantization.py
  18. 0 0
      src/llama_cookbook/configs/training.py
  19. 0 0
      src/llama_cookbook/configs/wandb.py
  20. 0 0
      src/llama_cookbook/data/__init__.py
  21. 0 0
      src/llama_cookbook/data/concatenator.py
  22. 0 0
      src/llama_cookbook/data/llama_guard/README.md
  23. 0 0
      src/llama_cookbook/data/llama_guard/__init__.py
  24. 0 0
      src/llama_cookbook/data/llama_guard/finetuning_data_formatter.py
  25. 0 0
      src/llama_cookbook/data/llama_guard/finetuning_data_formatter_example.py
  26. 0 0
      src/llama_cookbook/data/sampler.py
  27. 5 5
      src/llama_recipes/datasets/__init__.py
  28. 0 0
      src/llama_cookbook/datasets/alpaca_dataset.py
  29. 0 0
      src/llama_cookbook/datasets/custom_dataset.py
  30. 0 0
      src/llama_cookbook/datasets/grammar_dataset/__init__.py
  31. 0 0
      src/llama_cookbook/datasets/grammar_dataset/grammar_dataset.py
  32. 0 0
      src/llama_cookbook/datasets/grammar_dataset/grammar_dataset_process.ipynb
  33. 0 0
      src/llama_cookbook/datasets/samsum_dataset.py
  34. 2 2
      src/llama_recipes/datasets/toxicchat_dataset.py
  35. 8 8
      src/llama_recipes/finetuning.py
  36. 0 0
      src/llama_cookbook/inference/__init__.py
  37. 0 0
      src/llama_cookbook/inference/chat_utils.py
  38. 1 1
      src/llama_recipes/inference/checkpoint_converter_fsdp_hf.py
  39. 0 0
      src/llama_cookbook/inference/llm.py
  40. 2 2
      src/llama_recipes/inference/model_utils.py
  41. 0 0
      src/llama_cookbook/inference/prompt_format_utils.py
  42. 0 0
      src/llama_cookbook/inference/safety_utils.py
  43. 1 1
      src/llama_recipes/model_checkpointing/__init__.py
  44. 0 0
      src/llama_cookbook/model_checkpointing/checkpoint_handler.py
  45. 7 0
      src/llama_cookbook/policies/__init__.py
  46. 0 0
      src/llama_cookbook/policies/activation_checkpointing_functions.py
  47. 0 0
      src/llama_cookbook/policies/anyprecision_optimizer.py
  48. 0 0
      src/llama_cookbook/policies/mixed_precision.py
  49. 0 0
      src/llama_cookbook/policies/wrapping.py
  50. 0 0
      src/llama_cookbook/tools/README.md
  51. 0 0
      src/llama_cookbook/tools/compare_llama_weights.py
  52. 0 0
      src/llama_cookbook/tools/convert_hf_weights_to_llama.py
  53. 7 0
      src/llama_cookbook/utils/__init__.py
  54. 3 3
      src/llama_recipes/utils/config_utils.py
  55. 3 3
      src/llama_recipes/utils/dataset_utils.py
  56. 0 0
      src/llama_cookbook/utils/flop_utils.py
  57. 0 0
      src/llama_cookbook/utils/fsdp_utils.py
  58. 0 0
      src/llama_cookbook/utils/memory_utils.py
  59. 0 0
      src/llama_cookbook/utils/plot_metrics.py
  60. 4 4
      src/llama_recipes/utils/train_utils.py
  61. 0 8
      src/llama_recipes/configs/__init__.py
  62. 0 7
      src/llama_recipes/policies/__init__.py
  63. 0 7
      src/llama_recipes/utils/__init__.py
  64. 14 14
      src/tests/datasets/test_custom_dataset.py
  65. 8 8
      src/tests/datasets/test_grammar_datasets.py
  66. 9 9
      src/tests/datasets/test_samsum_datasets.py
  67. 26 26
      src/tests/test_batching.py
  68. 1 1
      src/tests/test_chat_completion.py
  69. 41 41
      src/tests/test_finetuning.py
  70. 1 1
      src/tests/test_finetuning_data_formatter.py
  71. 3 3
      src/tests/test_sampler.py
  72. 5 5
      src/tests/test_train_utils.py

+ 1 - 1
getting-started/README.md

@@ -6,4 +6,4 @@ If you are new to developing with Meta Llama models, this is where you should st
 * The [Prompt_Engineering_with_Llama](./Prompt_Engineering_with_Llama.ipynb) notebook showcases the various ways to elicit appropriate outputs from Llama. Take this notebook for a spin to get a feel for how Llama responds to different inputs and generation parameters.
 * The [inference](./inference/) folder contains scripts to deploy Llama for inference on server and mobile. See also [3p_integrations/vllm](../3p-integrations/vllm/) and [3p_integrations/tgi](../3p-integrations/tgi/) for hosting Llama on open-source model servers.
 * The [RAG](./RAG/) folder contains a simple Retrieval-Augmented Generation application using Llama.
-* The [finetuning](./finetuning/) folder contains resources to help you finetune Llama on your custom datasets, for both single- and multi-GPU setups. The scripts use the native llama-recipes finetuning code found in [finetuning.py](../src/llama_recipes/finetuning.py) which supports these features:
+* The [finetuning](./finetuning/) folder contains resources to help you finetune Llama on your custom datasets, for both single- and multi-GPU setups. The scripts use the native llama-cookbook finetuning code found in [finetuning.py](../src/llama_cookbook/finetuning.py) which supports these features:

+ 7 - 7
getting-started/finetuning/README.md

@@ -6,7 +6,7 @@ This folder contains instructions to fine-tune Meta Llama 3 on a
 * [single-GPU setup](./singlegpu_finetuning.md)
 * [multi-GPU setup](./multigpu_finetuning.md)
 
-using the canonical [finetuning script](../../src/llama_recipes/finetuning.py) in the llama-recipes package.
+using the canonical [finetuning script](../../src/llama_cookbook/finetuning.py) in the llama-cookbook package.
 
 If you are new to fine-tuning techniques, check out [an overview](./LLM_finetuning_overview.md).
 
@@ -17,10 +17,10 @@ If you are new to fine-tuning techniques, check out [an overview](./LLM_finetuni
 ## How to configure finetuning settings?
 
 > [!TIP]
-> All the setting defined in [config files](../../src/llama_recipes/configs/) can be passed as args through CLI when running the script, there is no need to change from config files directly.
+> All the setting defined in [config files](../../src/llama_cookbook/configs/) can be passed as args through CLI when running the script, there is no need to change from config files directly.
 
 
-* [Training config file](../../src/llama_recipes/configs/training.py) is the main config file that helps to specify the settings for our run and can be found in [configs folder](../../src/llama_recipes/configs/)
+* [Training config file](../../src/llama_cookbook/configs/training.py) is the main config file that helps to specify the settings for our run and can be found in [configs folder](../../src/llama_cookbook/configs/)
 
 It lets us specify the training settings for everything from `model_name` to `dataset_name`, `batch_size` and so on. Below is the list of supported settings:
 
@@ -71,11 +71,11 @@ It lets us specify the training settings for everything from `model_name` to `da
 
 ```
 
-* [Datasets config file](../../src/llama_recipes/configs/datasets.py) provides the available options for datasets.
+* [Datasets config file](../../src/llama_cookbook/configs/datasets.py) provides the available options for datasets.
 
-* [peft config file](../../src/llama_recipes/configs/peft.py) provides the supported PEFT methods and respective settings that can be modified. We currently support LoRA and Llama-Adapter. Please note that LoRA is the only technique which is supported in combination with FSDP.
+* [peft config file](../../src/llama_cookbook/configs/peft.py) provides the supported PEFT methods and respective settings that can be modified. We currently support LoRA and Llama-Adapter. Please note that LoRA is the only technique which is supported in combination with FSDP.
 
-* [FSDP config file](../../src/llama_recipes/configs/fsdp.py) provides FSDP settings such as:
+* [FSDP config file](../../src/llama_cookbook/configs/fsdp.py) provides FSDP settings such as:
 
     * `mixed_precision` boolean flag to specify using mixed precision, defatults to true.
 
@@ -102,7 +102,7 @@ It lets us specify the training settings for everything from `model_name` to `da
 You can enable [W&B](https://wandb.ai/) experiment tracking by using `use_wandb` flag as below. You can change the project name, entity and other `wandb.init` arguments in `wandb_config`.
 
 ```bash
-python -m llama_recipes.finetuning --use_peft --peft_method lora --quantization 8bit --model_name /path_of_model_folder/8B --output_dir Path/to/save/PEFT/model --use_wandb
+python -m llama_cookbook.finetuning --use_peft --peft_method lora --quantization 8bit --model_name /path_of_model_folder/8B --output_dir Path/to/save/PEFT/model --use_wandb
 ```
 You'll be able to access a dedicated project or run link on [wandb.ai](https://wandb.ai) and see your dashboard like the one below.
 <div style="display: flex;">

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 14 - 14
getting-started/finetuning/datasets/README.md


+ 6 - 6
getting-started/finetuning/multigpu_finetuning.md

@@ -3,14 +3,14 @@ This recipe steps you through how to finetune a Meta Llama 3 model on the text s
 
 
 ## Requirements
-Ensure that you have installed the llama-recipes package ([details](../../README.md#installing)).
+Ensure that you have installed the llama-cookbook package ([details](../../README.md#installing)).
 
 We will also need 2 packages:
 1. [PEFT](https://github.com/huggingface/peft) to use parameter-efficient finetuning.
 2. [FSDP](https://pytorch.org/tutorials/intermediate/FSDP_adavnced_tutorial.html) which helps us parallelize the training over multiple GPUs. [More details](./LLM_finetuning_overview.md#2-full-partial-parameter-finetuning).
 
 > [!NOTE]
-> The llama-recipes package will install PyTorch 2.0.1 version. In case you want to use FSDP with PEFT for multi GPU finetuning, please install the PyTorch nightlies ([details](../../README.md#pytorch-nightlies))
+> The llama-cookbook package will install PyTorch 2.0.1 version. In case you want to use FSDP with PEFT for multi GPU finetuning, please install the PyTorch nightlies ([details](../../README.md#pytorch-nightlies))
 >
 > INT8 quantization is not currently supported in FSDP
 
@@ -96,14 +96,14 @@ srun  torchrun --nproc_per_node 8 --rdzv_id $RANDOM --rdzv_backend c10d --rdzv_e
 Do not forget to adjust the number of nodes, ntasks and gpus-per-task in the top.
 
 ## Running with different datasets
-Currently 3 open source datasets are supported that can be found in [Datasets config file](../../src/llama_recipes/configs/datasets.py). You can also use your custom dataset (more info [here](./datasets/README.md)).
+Currently 3 open source datasets are supported that can be found in [Datasets config file](../../src/llama_cookbook/configs/datasets.py). You can also use your custom dataset (more info [here](./datasets/README.md)).
 
-* `grammar_dataset` : use this [notebook](../../src/llama_recipes/datasets/grammar_dataset/grammar_dataset_process.ipynb) to pull and process the Jfleg and C4 200M datasets for grammar checking.
+* `grammar_dataset` : use this [notebook](../../src/llama_cookbook/datasets/grammar_dataset/grammar_dataset_process.ipynb) to pull and process the Jfleg and C4 200M datasets for grammar checking.
 
 * `alpaca_dataset` : to get this open source data please download the `aplaca.json` to `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`
@@ -132,7 +132,7 @@ In case you are dealing with slower interconnect network between nodes, to reduc
 
 HSDP (Hybrid sharding Data Parallel) helps to define a hybrid sharding strategy where you can have FSDP within `sharding_group_size` which can be the minimum number of GPUs you can fit your model and DDP between the replicas of the model specified by `replica_group_size`.
 
-This will require to set the Sharding strategy in [fsdp config](../../src/llama_recipes/configs/fsdp.py) to `ShardingStrategy.HYBRID_SHARD` and specify two additional settings, `sharding_group_size` and `replica_group_size` where former specifies the sharding group size, number of GPUs that you model can fit into to form a replica of a model and latter specifies the replica group size, which is world_size/sharding_group_size.
+This will require to set the Sharding strategy in [fsdp config](../../src/llama_cookbook/configs/fsdp.py) to `ShardingStrategy.HYBRID_SHARD` and specify two additional settings, `sharding_group_size` and `replica_group_size` where former specifies the sharding group size, number of GPUs that you model can fit into to form a replica of a model and latter specifies the replica group size, which is world_size/sharding_group_size.
 
 ```bash
 

+ 5 - 5
getting-started/finetuning/singlegpu_finetuning.md

@@ -1,12 +1,12 @@
 # Fine-tuning with Single GPU
 This recipe steps you through how to finetune a Meta Llama 3 model on the text summarization task using the [samsum](https://huggingface.co/datasets/samsum) dataset on a single GPU.
 
-These are the instructions for using the canonical [finetuning script](../../src/llama_recipes/finetuning.py) in the llama-recipes package.
+These are the instructions for using the canonical [finetuning script](../../src/llama_cookbook/finetuning.py) in the llama-cookbook package.
 
 
 ## Requirements
 
-Ensure that you have installed the llama-recipes package.
+Ensure that you have installed the llama-cookbook package.
 
 To run fine-tuning on a single GPU, we will make use of two packages:
 1. [PEFT](https://github.com/huggingface/peft) to use parameter-efficient finetuning.
@@ -33,15 +33,15 @@ The args used in the command above are:
 
 ### How to run with different datasets?
 
-Currently 3 open source datasets are supported that can be found in [Datasets config file](../../src/llama_recipes/configs/datasets.py). You can also use your custom dataset (more info [here](./datasets/README.md)).
+Currently 3 open source datasets are supported that can be found in [Datasets config file](../../src/llama_cookbook/configs/datasets.py). You can also use your custom dataset (more info [here](./datasets/README.md)).
 
-* `grammar_dataset` : use this [notebook](../../src/llama_recipes/datasets/grammar_dataset/grammar_dataset_process.ipynb) to pull and process the Jfleg and C4 200M datasets for grammar checking.
+* `grammar_dataset` : use this [notebook](../../src/llama_cookbook/datasets/grammar_dataset/grammar_dataset_process.ipynb) to pull and process the Jfleg and C4 200M datasets for grammar checking.
 
 * `alpaca_dataset` : to get this open source data please download the `alpaca.json` to `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`

+ 3 - 3
getting-started/inference/local_inference/README.md

@@ -105,7 +105,7 @@ python inference.py --model_name <training_config.output_dir> --peft_model <trai
 
 ## Inference with FSDP checkpoints
 
-In case you have fine-tuned your model with pure FSDP and saved the checkpoints with "SHARDED_STATE_DICT" as shown [here](../../../src/llama_recipes/configs/fsdp.py), you can use this converter script to convert the FSDP Sharded checkpoints into HuggingFace checkpoints. This enables you to use the inference script normally as mentioned above.
+In case you have fine-tuned your model with pure FSDP and saved the checkpoints with "SHARDED_STATE_DICT" as shown [here](../../../src/llama_cookbook/configs/fsdp.py), you can use this converter script to convert the FSDP Sharded checkpoints into HuggingFace checkpoints. This enables you to use the inference script normally as mentioned above.
 **To convert the checkpoint use the following command**:
 
 This is helpful if you have fine-tuned you model using FSDP only as follows:
@@ -115,7 +115,7 @@ torchrun --nnodes 1 --nproc_per_node 8  recipes/quickstart/finetuning/finetuning
 ```
 Then convert your FSDP checkpoint to HuggingFace checkpoints using:
 ```bash
- python -m llama_recipes.inference.checkpoint_converter_fsdp_hf --fsdp_checkpoint_path  PATH/to/FSDP/Checkpoints --consolidated_model_path PATH/to/save/checkpoints --HF_model_path_or_name PATH/or/HF/model_name
+ python -m llama_cookbook.inference.checkpoint_converter_fsdp_hf --fsdp_checkpoint_path  PATH/to/FSDP/Checkpoints --consolidated_model_path PATH/to/save/checkpoints --HF_model_path_or_name PATH/or/HF/model_name
 
  # --HF_model_path_or_name specifies the HF Llama model name or path where it has config.json and tokenizer.json
  ```
@@ -130,4 +130,4 @@ python inference.py --model_name <training_config.output_dir> --prompt_file <tes
 
 ## Inference on large models like Meta Llama 405B
 The FP8 quantized variants of Meta Llama (i.e. meta-llama/Meta-Llama-3.1-405B-FP8 and meta-llama/Meta-Llama-3.1-405B-Instruct-FP8) can be executed on a single node with 8x80GB H100 using the scripts located in this folder.
-To run the unquantized Meta Llama 405B variants (i.e. meta-llama/Meta-Llama-3.1-405B and meta-llama/Meta-Llama-3.1-405B-Instruct) we need to use a multi-node setup for inference. The llama-recipes inference script currently does not allow multi-node inference. To run this model you can use vLLM with pipeline and tensor parallelism as showed in [this example](../../../3p-integrations/vllm/README.md).
+To run the unquantized Meta Llama 405B variants (i.e. meta-llama/Meta-Llama-3.1-405B and meta-llama/Meta-Llama-3.1-405B-Instruct) we need to use a multi-node setup for inference. The llama-cookbook inference script currently does not allow multi-node inference. To run this model you can use vLLM with pipeline and tensor parallelism as showed in [this example](../../../3p-integrations/vllm/README.md).

+ 3 - 3
getting-started/inference/local_inference/chat_completion/chat_completion.py

@@ -11,9 +11,9 @@ import sys
 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(

+ 2 - 2
pyproject.toml

@@ -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="hamidnazeri@meta.com" },
   { name="Matthias Reso", email="mreso@meta.com" },
@@ -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"]

+ 0 - 3
src/README.md

@@ -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

+ 2 - 2
src/docs/FAQ.md

@@ -36,13 +36,13 @@ Here we discuss frequently asked questions that may occur and we found useful al
     os.environ['PYTORCH_CUDA_ALLOC_CONF']='expandable_segments:True'
 
     ```
-    We also added this environment variable in `setup_environ_flags` of the [train_utils.py](../llama_recipes/utils/train_utils.py), feel free to uncomment it if required.
+    We also added this environment variable in `setup_environ_flags` of the [train_utils.py](../llama_cookbook/utils/train_utils.py), feel free to uncomment it if required.
 
 8. Additional debugging flags?
 
     The environment variable `TORCH_DISTRIBUTED_DEBUG` can be used to trigger additional useful logging and collective synchronization checks to ensure all ranks are synchronized appropriately. `TORCH_DISTRIBUTED_DEBUG` can be set to either OFF (default), INFO, or DETAIL depending on the debugging level required. Please note that the most verbose option, DETAIL may impact the application performance and thus should only be used when debugging issues.
 
-    We also added this environment variable in `setup_environ_flags` of the [train_utils.py](../llama_recipes/utils/train_utils.py), feel free to uncomment it if required.
+    We also added this environment variable in `setup_environ_flags` of the [train_utils.py](../llama_cookbook/utils/train_utils.py), feel free to uncomment it if required.
 
 9. I am getting import errors when running inference.
 

+ 16 - 16
src/docs/multi_gpu.md

@@ -10,7 +10,7 @@ Given the combination of PEFT and FSDP, we would be able to fine tune a Meta Lla
 For big models like 405B we will need to fine-tune in a multi-node setup even if 4bit quantization is enabled.
 
 ## Requirements
-To run the examples, make sure to install the llama-recipes package and clone the github repository in order to use the provided [`finetuning.py`](../../getting-started/finetuning/finetuning.py) script with torchrun (See [README.md](../README.md) for details).
+To run the examples, make sure to install the llama-cookbook package and clone the github repository in order to use the provided [`finetuning.py`](../../getting-started/finetuning/finetuning.py) script with torchrun (See [README.md](../README.md) for details).
 
 ## How to run it
 
@@ -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
 
 ```
 
@@ -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
@@ -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
 
 ```
 
@@ -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
 
 ```
 
@@ -79,21 +79,21 @@ 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.
 
 ```
 
 ## How to run with different datasets?
 
-Currently 4 datasets are supported that can be found in [Datasets config file](../llama_recipes/configs/datasets.py).
+Currently 4 datasets are supported that can be found in [Datasets config file](../llama_cookbook/configs/datasets.py).
 
-* `grammar_dataset` : use this [notebook](../llama_recipes/datasets/grammar_dataset/grammar_dataset_process.ipynb) to pull and process theJfleg and C4 200M datasets for grammar checking.
+* `grammar_dataset` : use this [notebook](../llama_cookbook/datasets/grammar_dataset/grammar_dataset_process.ipynb) to pull and process theJfleg and C4 200M datasets for grammar checking.
 
 * `alpaca_dataset` : to get this open source data please download the `aplaca.json` to `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`
@@ -102,22 +102,22 @@ 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
 
 ```
 
 ## Where to configure settings?
 
-* [Training config file](../llama_recipes/configs/training.py) is the main config file that helps to specify the settings for our run and can be found in [configs folder](../llama_recipes/configs/)
+* [Training config file](../llama_cookbook/configs/training.py) is the main config file that helps to specify the settings for our run and can be found in [configs folder](../llama_cookbook/configs/)
 
 It lets us specify the training settings for everything from `model_name` to `dataset_name`, `batch_size` and so on. Below is the list of supported settings:
 
@@ -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.
 

+ 11 - 11
src/docs/single_gpu.md

@@ -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:
@@ -35,14 +35,14 @@ The args used in the command above are:
 
 ## How to run with different datasets?
 
-Currently 4 datasets are supported that can be found in [Datasets config file](../llama_recipes/configs/datasets.py).
+Currently 4 datasets are supported that can be found in [Datasets config file](../llama_cookbook/configs/datasets.py).
 
-* `grammar_dataset` : use this [notebook](../llama_recipes/datasets/grammar_dataset/grammar_dataset_process.ipynb) to pull and process theJfleg and C4 200M datasets for grammar checking.
+* `grammar_dataset` : use this [notebook](../llama_cookbook/datasets/grammar_dataset/grammar_dataset_process.ipynb) to pull and process theJfleg and C4 200M datasets for grammar checking.
 
 * `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`
@@ -52,22 +52,22 @@ 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
 
 ```
 
 ## Where to configure settings?
 
-* [Training config file](../llama_recipes/configs/training.py) is the main config file that help to specify the settings for our run can be found in
+* [Training config file](../llama_cookbook/configs/training.py) is the main config file that help to specify the settings for our run can be found in
 
 It let us specify the training settings, everything from `model_name` to `dataset_name`, `batch_size` etc. can be set here. Below is the list of supported settings:
 
@@ -117,10 +117,10 @@ It let us specify the training settings, everything from `model_name` to `datase
 
 ```
 
-* [Datasets config file](../llama_recipes/configs/datasets.py)
-    ../src/llama_recipes/configs/datasets.py) provides the available options for datasets.
+* [Datasets config file](../llama_cookbook/configs/datasets.py)
+    ../src/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.
 
 ## FLOPS Counting and Pytorch Profiling
 

+ 8 - 0
src/llama_cookbook/configs/__init__.py

@@ -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

src/llama_recipes/configs/datasets.py → src/llama_cookbook/configs/datasets.py


src/llama_recipes/configs/fsdp.py → src/llama_cookbook/configs/fsdp.py


src/llama_recipes/configs/peft.py → src/llama_cookbook/configs/peft.py


src/llama_recipes/configs/quantization.py → src/llama_cookbook/configs/quantization.py


src/llama_recipes/configs/training.py → src/llama_cookbook/configs/training.py


src/llama_recipes/configs/wandb.py → src/llama_cookbook/configs/wandb.py


src/llama_recipes/data/__init__.py → src/llama_cookbook/data/__init__.py


src/llama_recipes/data/concatenator.py → src/llama_cookbook/data/concatenator.py


src/llama_recipes/data/llama_guard/README.md → src/llama_cookbook/data/llama_guard/README.md


src/llama_recipes/data/llama_guard/__init__.py → src/llama_cookbook/data/llama_guard/__init__.py


src/llama_recipes/data/llama_guard/finetuning_data_formatter.py → src/llama_cookbook/data/llama_guard/finetuning_data_formatter.py


src/llama_recipes/data/llama_guard/finetuning_data_formatter_example.py → src/llama_cookbook/data/llama_guard/finetuning_data_formatter_example.py


src/llama_recipes/data/sampler.py → src/llama_cookbook/data/sampler.py


+ 5 - 5
src/llama_recipes/datasets/__init__.py

@@ -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,

src/llama_recipes/datasets/alpaca_dataset.py → src/llama_cookbook/datasets/alpaca_dataset.py


src/llama_recipes/datasets/custom_dataset.py → src/llama_cookbook/datasets/custom_dataset.py


src/llama_recipes/datasets/grammar_dataset/__init__.py → src/llama_cookbook/datasets/grammar_dataset/__init__.py


src/llama_recipes/datasets/grammar_dataset/grammar_dataset.py → src/llama_cookbook/datasets/grammar_dataset/grammar_dataset.py


src/llama_recipes/datasets/grammar_dataset/grammar_dataset_process.ipynb → src/llama_cookbook/datasets/grammar_dataset/grammar_dataset_process.ipynb


src/llama_recipes/datasets/samsum_dataset.py → src/llama_cookbook/datasets/samsum_dataset.py


+ 2 - 2
src/llama_recipes/datasets/toxicchat_dataset.py

@@ -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
 
@@ -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):

+ 8 - 8
src/llama_recipes/finetuning.py

@@ -13,29 +13,29 @@ import torch
 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,

src/llama_recipes/inference/__init__.py → src/llama_cookbook/inference/__init__.py


src/llama_recipes/inference/chat_utils.py → src/llama_cookbook/inference/chat_utils.py


+ 1 - 1
src/llama_recipes/inference/checkpoint_converter_fsdp_hf.py

@@ -9,7 +9,7 @@ import sys
 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
 

src/llama_recipes/inference/llm.py → src/llama_cookbook/inference/llm.py


+ 2 - 2
src/llama_recipes/inference/model_utils.py

@@ -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,

src/llama_recipes/inference/prompt_format_utils.py → src/llama_cookbook/inference/prompt_format_utils.py


src/llama_recipes/inference/safety_utils.py → src/llama_cookbook/inference/safety_utils.py


+ 1 - 1
src/llama_recipes/model_checkpointing/__init__.py

@@ -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,

src/llama_recipes/model_checkpointing/checkpoint_handler.py → src/llama_cookbook/model_checkpointing/checkpoint_handler.py


+ 7 - 0
src/llama_cookbook/policies/__init__.py

@@ -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

src/llama_recipes/policies/activation_checkpointing_functions.py → src/llama_cookbook/policies/activation_checkpointing_functions.py


src/llama_recipes/policies/anyprecision_optimizer.py → src/llama_cookbook/policies/anyprecision_optimizer.py


src/llama_recipes/policies/mixed_precision.py → src/llama_cookbook/policies/mixed_precision.py


src/llama_recipes/policies/wrapping.py → src/llama_cookbook/policies/wrapping.py


src/llama_recipes/tools/README.md → src/llama_cookbook/tools/README.md


src/llama_recipes/tools/compare_llama_weights.py → src/llama_cookbook/tools/compare_llama_weights.py


src/llama_recipes/tools/convert_hf_weights_to_llama.py → src/llama_cookbook/tools/convert_hf_weights_to_llama.py


+ 7 - 0
src/llama_cookbook/utils/__init__.py

@@ -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 *

+ 3 - 3
src/llama_recipes/utils/config_utils.py

@@ -15,9 +15,9 @@ from peft import (
 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)):

+ 3 - 3
src/llama_recipes/utils/dataset_utils.py

@@ -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(

src/llama_recipes/utils/flop_utils.py → src/llama_cookbook/utils/flop_utils.py


src/llama_recipes/utils/fsdp_utils.py → src/llama_cookbook/utils/fsdp_utils.py


src/llama_recipes/utils/memory_utils.py → src/llama_cookbook/utils/memory_utils.py


src/llama_recipes/utils/plot_metrics.py → src/llama_cookbook/utils/plot_metrics.py


+ 4 - 4
src/llama_recipes/utils/train_utils.py

@@ -20,11 +20,11 @@ from transformers import LlamaTokenizer
 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"

+ 0 - 8
src/llama_recipes/configs/__init__.py

@@ -1,8 +0,0 @@
-# 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.configs.peft import lora_config, llama_adapter_config, prefix_config
-from llama_recipes.configs.fsdp import fsdp_config
-from llama_recipes.configs.training import train_config
-from llama_recipes.configs.wandb import wandb_config
-from llama_recipes.configs.quantization import quantization_config

+ 0 - 7
src/llama_recipes/policies/__init__.py

@@ -1,7 +0,0 @@
-# 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.policies.mixed_precision import *
-from llama_recipes.policies.wrapping import *
-from llama_recipes.policies.activation_checkpointing_functions import apply_fsdp_checkpointing
-from llama_recipes.policies.anyprecision_optimizer import AnyPrecisionAdamW

+ 0 - 7
src/llama_recipes/utils/__init__.py

@@ -1,7 +0,0 @@
-# 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.utils.memory_utils import MemoryTrace
-from llama_recipes.utils.dataset_utils import *
-from llama_recipes.utils.fsdp_utils import fsdp_auto_wrap_policy, hsdp_device_mesh
-from llama_recipes.utils.train_utils import *

+ 14 - 14
src/tests/datasets/test_custom_dataset.py

@@ -36,13 +36,13 @@ def check_padded_entry(batch, tokenizer):
 
 @pytest.mark.skip(reason="Flakey due to random dataset order @todo fix order")
 @pytest.mark.skip_missing_tokenizer
-@patch('llama_recipes.finetuning.train')
-@patch('llama_recipes.finetuning.AutoTokenizer')
-@patch('llama_recipes.finetuning.LlamaForCausalLM.from_pretrained')
-@patch('llama_recipes.finetuning.optim.AdamW')
-@patch('llama_recipes.finetuning.StepLR')
+@patch('llama_cookbook.finetuning.train')
+@patch('llama_cookbook.finetuning.AutoTokenizer')
+@patch('llama_cookbook.finetuning.LlamaForCausalLM.from_pretrained')
+@patch('llama_cookbook.finetuning.optim.AdamW')
+@patch('llama_cookbook.finetuning.StepLR')
 def test_custom_dataset(step_lr, optimizer, get_model, tokenizer, train, mocker, setup_tokenizer, llama_version):
-    from llama_recipes.finetuning import main
+    from llama_cookbook.finetuning import main
 
     setup_tokenizer(tokenizer)
 
@@ -96,14 +96,14 @@ def test_custom_dataset(step_lr, optimizer, get_model, tokenizer, train, mocker,
 
 
 
-@patch('llama_recipes.finetuning.train')
-@patch('llama_recipes.finetuning.AutoConfig.from_pretrained')
-@patch('llama_recipes.finetuning.LlamaForCausalLM.from_pretrained')
-@patch('llama_recipes.finetuning.AutoTokenizer.from_pretrained')
-@patch('llama_recipes.finetuning.optim.AdamW')
-@patch('llama_recipes.finetuning.StepLR')
+@patch('llama_cookbook.finetuning.train')
+@patch('llama_cookbook.finetuning.AutoConfig.from_pretrained')
+@patch('llama_cookbook.finetuning.LlamaForCausalLM.from_pretrained')
+@patch('llama_cookbook.finetuning.AutoTokenizer.from_pretrained')
+@patch('llama_cookbook.finetuning.optim.AdamW')
+@patch('llama_cookbook.finetuning.StepLR')
 def test_unknown_dataset_error(step_lr, optimizer, tokenizer, get_model, get_config, train, mocker, llama_version):
-    from llama_recipes.finetuning import main
+    from llama_cookbook.finetuning import main
 
     tokenizer.return_value = mocker.MagicMock(side_effect=lambda x: {"input_ids":[len(x)*[0,]], "attention_mask": [len(x)*[0,]]})
     get_model.return_value.get_input_embeddings.return_value.weight.shape = [32000 if "Llama-2" in llama_version else 128256]
@@ -119,7 +119,7 @@ def test_unknown_dataset_error(step_lr, optimizer, tokenizer, get_model, get_con
         main(**kwargs)
 
 @pytest.mark.skip_missing_tokenizer
-@patch('llama_recipes.finetuning.AutoTokenizer')
+@patch('llama_cookbook.finetuning.AutoTokenizer')
 def test_tokenize_dialog(tokenizer, monkeypatch, setup_tokenizer, llama_version):
     monkeypatch.syspath_prepend("getting-started/finetuning/datasets/")
     from custom_dataset import tokenize_dialog

+ 8 - 8
src/tests/datasets/test_grammar_datasets.py

@@ -5,19 +5,19 @@ from pathlib import Path
 import pytest
 from unittest.mock import patch
 
-DATA_DIR = Path(__file__).parents[2] / "llama_recipes/datasets/grammar_dataset/"
+DATA_DIR = Path(__file__).parents[2] / "llama_cookbook/datasets/grammar_dataset/"
 
 @pytest.mark.skip_missing_tokenizer
 @pytest.mark.skipif(not Path(DATA_DIR / "grammar_validation.csv").exists(), reason="grammar_validation.csv not found")
 @pytest.mark.skipif(not Path(DATA_DIR / "gtrain_10k.csv").exists(), reason="gtrain_10k.csv not found")
-@patch('llama_recipes.finetuning.train')
-@patch('llama_recipes.finetuning.AutoTokenizer')
-@patch('llama_recipes.finetuning.AutoConfig.from_pretrained')
-@patch('llama_recipes.finetuning.LlamaForCausalLM.from_pretrained')
-@patch('llama_recipes.finetuning.optim.AdamW')
-@patch('llama_recipes.finetuning.StepLR')
+@patch('llama_cookbook.finetuning.train')
+@patch('llama_cookbook.finetuning.AutoTokenizer')
+@patch('llama_cookbook.finetuning.AutoConfig.from_pretrained')
+@patch('llama_cookbook.finetuning.LlamaForCausalLM.from_pretrained')
+@patch('llama_cookbook.finetuning.optim.AdamW')
+@patch('llama_cookbook.finetuning.StepLR')
 def test_grammar_dataset(step_lr, optimizer, get_model, get_config, tokenizer, train, setup_tokenizer, llama_version):
-    from llama_recipes.finetuning import main
+    from llama_cookbook.finetuning import main
 
     setup_tokenizer(tokenizer)
     get_model.return_value.get_input_embeddings.return_value.weight.shape = [32000 if "Llama-2" in llama_version else 128256]

+ 9 - 9
src/tests/datasets/test_samsum_datasets.py

@@ -19,14 +19,14 @@ except ValueError:
 
 @pytest.mark.skipif(SAMSUM_UNAVAILABLE, reason="Samsum dataset is unavailable")
 @pytest.mark.skip_missing_tokenizer
-@patch('llama_recipes.finetuning.train')
-@patch('llama_recipes.finetuning.AutoTokenizer')
-@patch("llama_recipes.finetuning.AutoConfig.from_pretrained")
-@patch("llama_recipes.finetuning.AutoProcessor")
-@patch("llama_recipes.finetuning.MllamaForConditionalGeneration.from_pretrained")
-@patch('llama_recipes.finetuning.LlamaForCausalLM.from_pretrained')
-@patch('llama_recipes.finetuning.optim.AdamW')
-@patch('llama_recipes.finetuning.StepLR')
+@patch('llama_cookbook.finetuning.train')
+@patch('llama_cookbook.finetuning.AutoTokenizer')
+@patch("llama_cookbook.finetuning.AutoConfig.from_pretrained")
+@patch("llama_cookbook.finetuning.AutoProcessor")
+@patch("llama_cookbook.finetuning.MllamaForConditionalGeneration.from_pretrained")
+@patch('llama_cookbook.finetuning.LlamaForCausalLM.from_pretrained')
+@patch('llama_cookbook.finetuning.optim.AdamW')
+@patch('llama_cookbook.finetuning.StepLR')
 def test_samsum_dataset(
     step_lr,
     optimizer,
@@ -40,7 +40,7 @@ def test_samsum_dataset(
     setup_tokenizer,
     llama_version,
     ):
-    from llama_recipes.finetuning import main
+    from llama_cookbook.finetuning import main
 
     setup_tokenizer(tokenizer)
     get_model.return_value.get_input_embeddings.return_value.weight.shape = [32000 if "Llama-2" in llama_version else 128256]

+ 26 - 26
src/tests/test_batching.py

@@ -31,15 +31,15 @@ fake_samsum_dataset = 2048*[{'id': '420',
  'summary': 'Mario and Luigi are going to save the princess.'}]
 
 @pytest.mark.skip_missing_tokenizer
-@patch('llama_recipes.finetuning.train')
-@patch('llama_recipes.finetuning.AutoTokenizer')
-@patch("llama_recipes.finetuning.AutoConfig.from_pretrained")
-@patch("llama_recipes.finetuning.AutoProcessor")
-@patch("llama_recipes.finetuning.MllamaForConditionalGeneration.from_pretrained")
-@patch('llama_recipes.finetuning.LlamaForCausalLM.from_pretrained')
-@patch('llama_recipes.finetuning.optim.AdamW')
-@patch('llama_recipes.finetuning.StepLR')
-@patch('llama_recipes.datasets.samsum_dataset.datasets')
+@patch('llama_cookbook.finetuning.train')
+@patch('llama_cookbook.finetuning.AutoTokenizer')
+@patch("llama_cookbook.finetuning.AutoConfig.from_pretrained")
+@patch("llama_cookbook.finetuning.AutoProcessor")
+@patch("llama_cookbook.finetuning.MllamaForConditionalGeneration.from_pretrained")
+@patch('llama_cookbook.finetuning.LlamaForCausalLM.from_pretrained')
+@patch('llama_cookbook.finetuning.optim.AdamW')
+@patch('llama_cookbook.finetuning.StepLR')
+@patch('llama_cookbook.datasets.samsum_dataset.datasets')
 def test_packing(
     datasets,
     step_lr,
@@ -55,7 +55,7 @@ def test_packing(
     llama_version,
     model_type,
     ):
-    from llama_recipes.finetuning import main
+    from llama_cookbook.finetuning import main
 
     setup_tokenizer(tokenizer)
     setup_processor(processor)
@@ -101,21 +101,21 @@ def test_packing(
 
 
 @pytest.mark.skip_missing_tokenizer
-@patch("llama_recipes.utils.train_utils.torch.cuda.is_bf16_supported")
-@patch("llama_recipes.finetuning.torch.cuda.is_available")
-@patch('llama_recipes.finetuning.train')
-@patch('llama_recipes.finetuning.AutoTokenizer')
-@patch("llama_recipes.finetuning.AutoConfig.from_pretrained")
-@patch("llama_recipes.finetuning.AutoProcessor")
-@patch("llama_recipes.finetuning.MllamaForConditionalGeneration.from_pretrained")
-@patch('llama_recipes.finetuning.LlamaForCausalLM.from_pretrained')
-@patch('llama_recipes.finetuning.optim.AdamW')
-@patch('llama_recipes.finetuning.StepLR')
-@patch('llama_recipes.finetuning.setup')
-@patch('llama_recipes.finetuning.FSDP')
-@patch('llama_recipes.finetuning.torch.distributed.is_initialized')
-@patch('llama_recipes.utils.config_utils.dist')
-@patch('llama_recipes.datasets.samsum_dataset.datasets')
+@patch("llama_cookbook.utils.train_utils.torch.cuda.is_bf16_supported")
+@patch("llama_cookbook.finetuning.torch.cuda.is_available")
+@patch('llama_cookbook.finetuning.train')
+@patch('llama_cookbook.finetuning.AutoTokenizer')
+@patch("llama_cookbook.finetuning.AutoConfig.from_pretrained")
+@patch("llama_cookbook.finetuning.AutoProcessor")
+@patch("llama_cookbook.finetuning.MllamaForConditionalGeneration.from_pretrained")
+@patch('llama_cookbook.finetuning.LlamaForCausalLM.from_pretrained')
+@patch('llama_cookbook.finetuning.optim.AdamW')
+@patch('llama_cookbook.finetuning.StepLR')
+@patch('llama_cookbook.finetuning.setup')
+@patch('llama_cookbook.finetuning.FSDP')
+@patch('llama_cookbook.finetuning.torch.distributed.is_initialized')
+@patch('llama_cookbook.utils.config_utils.dist')
+@patch('llama_cookbook.datasets.samsum_dataset.datasets')
 def test_distributed_packing(
     datasets,
     dist,
@@ -138,7 +138,7 @@ def test_distributed_packing(
     model_type,
     ):
     import os
-    from llama_recipes.finetuning import main
+    from llama_cookbook.finetuning import main
 
     setup_tokenizer(tokenizer)
     setup_processor(processor)

+ 1 - 1
src/tests/test_chat_completion.py

@@ -5,7 +5,7 @@ from unittest.mock import patch
 
 import pytest
 import torch
-from llama_recipes.inference.chat_utils import read_dialogs_from_file
+from llama_cookbook.inference.chat_utils import read_dialogs_from_file
 
 ROOT_DIR = Path(__file__).parents[2]
 CHAT_COMPLETION_DIR = ROOT_DIR / "getting-started/inference/local_inference/chat_completion/"

+ 41 - 41
src/tests/test_finetuning.py

@@ -9,9 +9,9 @@ from unittest.mock import patch
 import pytest
 
 import torch
-from llama_recipes.data.sampler import LengthBasedBatchSampler
+from llama_cookbook.data.sampler import LengthBasedBatchSampler
 
-from llama_recipes.finetuning import main
+from llama_cookbook.finetuning import main
 from pytest import approx
 from torch.optim import AdamW
 from torch.utils.data.dataloader import DataLoader
@@ -32,18 +32,18 @@ def get_fake_dataset():
     ]
 
 
-@patch("llama_recipes.finetuning.torch.cuda.is_available")
-@patch("llama_recipes.finetuning.train")
-@patch("llama_recipes.finetuning.MllamaForConditionalGeneration.from_pretrained")
-@patch("llama_recipes.finetuning.AutoProcessor.from_pretrained")
-@patch("llama_recipes.finetuning.LlamaForCausalLM.from_pretrained")
-@patch("llama_recipes.finetuning.AutoConfig.from_pretrained")
-@patch("llama_recipes.finetuning.AutoTokenizer.from_pretrained")
-@patch("llama_recipes.finetuning.get_preprocessed_dataset")
-@patch("llama_recipes.finetuning.generate_peft_config")
-@patch("llama_recipes.finetuning.get_peft_model")
-@patch("llama_recipes.finetuning.optim.AdamW")
-@patch("llama_recipes.finetuning.StepLR")
+@patch("llama_cookbook.finetuning.torch.cuda.is_available")
+@patch("llama_cookbook.finetuning.train")
+@patch("llama_cookbook.finetuning.MllamaForConditionalGeneration.from_pretrained")
+@patch("llama_cookbook.finetuning.AutoProcessor.from_pretrained")
+@patch("llama_cookbook.finetuning.LlamaForCausalLM.from_pretrained")
+@patch("llama_cookbook.finetuning.AutoConfig.from_pretrained")
+@patch("llama_cookbook.finetuning.AutoTokenizer.from_pretrained")
+@patch("llama_cookbook.finetuning.get_preprocessed_dataset")
+@patch("llama_cookbook.finetuning.generate_peft_config")
+@patch("llama_cookbook.finetuning.get_peft_model")
+@patch("llama_cookbook.finetuning.optim.AdamW")
+@patch("llama_cookbook.finetuning.StepLR")
 @pytest.mark.parametrize("cuda_is_available", [True, False])
 @pytest.mark.parametrize("run_validation", [True, False])
 @pytest.mark.parametrize("use_peft", [True, False])
@@ -107,15 +107,15 @@ def test_finetuning(
         assert model.return_value.to.call_count == 0
 
 
-@patch("llama_recipes.finetuning.get_peft_model")
-@patch("llama_recipes.finetuning.setup")
-@patch("llama_recipes.finetuning.train")
-@patch("llama_recipes.finetuning.MllamaForConditionalGeneration.from_pretrained")
-@patch("llama_recipes.finetuning.AutoProcessor.from_pretrained")
-@patch("llama_recipes.finetuning.LlamaForCausalLM.from_pretrained")
-@patch("llama_recipes.finetuning.AutoConfig.from_pretrained")
-@patch("llama_recipes.finetuning.AutoTokenizer.from_pretrained")
-@patch("llama_recipes.finetuning.get_preprocessed_dataset")
+@patch("llama_cookbook.finetuning.get_peft_model")
+@patch("llama_cookbook.finetuning.setup")
+@patch("llama_cookbook.finetuning.train")
+@patch("llama_cookbook.finetuning.MllamaForConditionalGeneration.from_pretrained")
+@patch("llama_cookbook.finetuning.AutoProcessor.from_pretrained")
+@patch("llama_cookbook.finetuning.LlamaForCausalLM.from_pretrained")
+@patch("llama_cookbook.finetuning.AutoConfig.from_pretrained")
+@patch("llama_cookbook.finetuning.AutoTokenizer.from_pretrained")
+@patch("llama_cookbook.finetuning.get_preprocessed_dataset")
 def test_finetuning_peft_llama_adapter(
     get_dataset,
     tokenizer,
@@ -165,15 +165,15 @@ def test_finetuning_peft_llama_adapter(
         main(**kwargs)
 
 
-@patch("llama_recipes.finetuning.train")
-@patch("llama_recipes.finetuning.MllamaForConditionalGeneration.from_pretrained")
-@patch("llama_recipes.finetuning.AutoProcessor.from_pretrained")
-@patch("llama_recipes.finetuning.LlamaForCausalLM.from_pretrained")
-@patch("llama_recipes.finetuning.AutoConfig.from_pretrained")
-@patch("llama_recipes.finetuning.AutoTokenizer.from_pretrained")
-@patch("llama_recipes.finetuning.get_preprocessed_dataset")
-@patch("llama_recipes.finetuning.get_peft_model")
-@patch("llama_recipes.finetuning.StepLR")
+@patch("llama_cookbook.finetuning.train")
+@patch("llama_cookbook.finetuning.MllamaForConditionalGeneration.from_pretrained")
+@patch("llama_cookbook.finetuning.AutoProcessor.from_pretrained")
+@patch("llama_cookbook.finetuning.LlamaForCausalLM.from_pretrained")
+@patch("llama_cookbook.finetuning.AutoConfig.from_pretrained")
+@patch("llama_cookbook.finetuning.AutoTokenizer.from_pretrained")
+@patch("llama_cookbook.finetuning.get_preprocessed_dataset")
+@patch("llama_cookbook.finetuning.get_peft_model")
+@patch("llama_cookbook.finetuning.StepLR")
 def test_finetuning_weight_decay(
     step_lr,
     get_peft_model,
@@ -210,15 +210,15 @@ def test_finetuning_weight_decay(
     assert optimizer.state_dict()["param_groups"][0]["weight_decay"] == approx(0.01)
 
 
-@patch("llama_recipes.finetuning.train")
-@patch("llama_recipes.finetuning.MllamaForConditionalGeneration.from_pretrained")
-@patch("llama_recipes.finetuning.AutoProcessor.from_pretrained")
-@patch("llama_recipes.finetuning.LlamaForCausalLM.from_pretrained")
-@patch("llama_recipes.finetuning.AutoConfig.from_pretrained")
-@patch("llama_recipes.finetuning.AutoTokenizer.from_pretrained")
-@patch("llama_recipes.finetuning.get_preprocessed_dataset")
-@patch("llama_recipes.finetuning.optim.AdamW")
-@patch("llama_recipes.finetuning.StepLR")
+@patch("llama_cookbook.finetuning.train")
+@patch("llama_cookbook.finetuning.MllamaForConditionalGeneration.from_pretrained")
+@patch("llama_cookbook.finetuning.AutoProcessor.from_pretrained")
+@patch("llama_cookbook.finetuning.LlamaForCausalLM.from_pretrained")
+@patch("llama_cookbook.finetuning.AutoConfig.from_pretrained")
+@patch("llama_cookbook.finetuning.AutoTokenizer.from_pretrained")
+@patch("llama_cookbook.finetuning.get_preprocessed_dataset")
+@patch("llama_cookbook.finetuning.optim.AdamW")
+@patch("llama_cookbook.finetuning.StepLR")
 def test_batching_strategy(
     step_lr,
     optimizer,

+ 1 - 1
src/tests/test_finetuning_data_formatter.py

@@ -5,7 +5,7 @@ from enum import Enum
 import unittest
 from typing import Optional, List
 
-from llama_recipes.data.llama_guard.finetuning_data_formatter import (
+from llama_cookbook.data.llama_guard.finetuning_data_formatter import (
     AugmentationConfigs,
     Category,
     create_formatted_finetuning_examples,

+ 3 - 3
src/tests/test_sampler.py

@@ -6,8 +6,8 @@ import pytest
 
 import torch
 
-from llama_recipes.data.sampler import LengthBasedBatchSampler
-from llama_recipes.data.sampler import DistributedLengthBasedBatchSampler
+from llama_cookbook.data.sampler import LengthBasedBatchSampler
+from llama_cookbook.data.sampler import DistributedLengthBasedBatchSampler
 
 SAMPLES = 33
 
@@ -83,4 +83,4 @@ def test_dist_batch_sampling(dataset, batch_size):
     
     assert ids_1.isdisjoint(ids_2)
     assert len(ids_1)+len(ids_2) > 0
-    assert len(ids_1)+len(ids_2) == len(dataset) // batch_size  *  batch_size 
+    assert len(ids_1)+len(ids_2) == len(dataset) // batch_size  *  batch_size 

+ 5 - 5
src/tests/test_train_utils.py

@@ -9,7 +9,7 @@ import torch
 import os
 import shutil
 
-from llama_recipes.utils.train_utils import train
+from llama_cookbook.utils.train_utils import train
 
 TEMP_OUTPUT_DIR = os.getcwd() + "/tmp"
 
@@ -23,10 +23,10 @@ def temp_output_dir():
     shutil.rmtree(temp_output_dir)
 
 
-@patch("llama_recipes.utils.train_utils.MemoryTrace")
-@patch("llama_recipes.utils.train_utils.nullcontext")
-@patch("llama_recipes.utils.train_utils.torch.cuda.amp.GradScaler")
-@patch("llama_recipes.utils.train_utils.torch.cuda.amp.autocast")
+@patch("llama_cookbook.utils.train_utils.MemoryTrace")
+@patch("llama_cookbook.utils.train_utils.nullcontext")
+@patch("llama_cookbook.utils.train_utils.torch.cuda.amp.GradScaler")
+@patch("llama_cookbook.utils.train_utils.torch.cuda.amp.autocast")
 def test_gradient_accumulation(
     autocast,
     scaler,