litgpt 0.1.0.dev1__tar.gz → 0.2.0.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. litgpt-0.2.0.dev0/PKG-INFO +639 -0
  2. litgpt-0.2.0.dev0/README.md +404 -0
  3. {litgpt-0.1.0.dev1/lit_gpt → litgpt-0.2.0.dev0/litgpt}/__init__.py +7 -6
  4. litgpt-0.2.0.dev0/litgpt/__main__.py +133 -0
  5. {litgpt-0.1.0.dev1/lit_gpt → litgpt-0.2.0.dev0/litgpt}/adapter.py +8 -8
  6. {litgpt-0.1.0.dev1/lit_gpt → litgpt-0.2.0.dev0/litgpt}/adapter_v2.py +14 -14
  7. {litgpt-0.1.0.dev1/lit_gpt → litgpt-0.2.0.dev0/litgpt}/args.py +13 -31
  8. litgpt-0.2.0.dev0/litgpt/chat/__init__.py +0 -0
  9. litgpt-0.2.0.dev0/litgpt/chat/base.py +198 -0
  10. {litgpt-0.1.0.dev1/lit_gpt → litgpt-0.2.0.dev0/litgpt}/config.py +178 -159
  11. litgpt-0.2.0.dev0/litgpt/data/__init__.py +36 -0
  12. litgpt-0.2.0.dev0/litgpt/data/alpaca.py +139 -0
  13. litgpt-0.2.0.dev0/litgpt/data/alpaca_2k.py +52 -0
  14. litgpt-0.2.0.dev0/litgpt/data/alpaca_gpt4.py +23 -0
  15. litgpt-0.2.0.dev0/litgpt/data/base.py +123 -0
  16. litgpt-0.2.0.dev0/litgpt/data/deita.py +114 -0
  17. litgpt-0.2.0.dev0/litgpt/data/dolly.py +80 -0
  18. litgpt-0.2.0.dev0/litgpt/data/flan.py +189 -0
  19. litgpt-0.2.0.dev0/litgpt/data/json_data.py +142 -0
  20. litgpt-0.2.0.dev0/litgpt/data/lima.py +130 -0
  21. litgpt-0.2.0.dev0/litgpt/data/lit_data.py +60 -0
  22. litgpt-0.2.0.dev0/litgpt/data/longform.py +90 -0
  23. litgpt-0.2.0.dev0/litgpt/data/openwebtext.py +109 -0
  24. litgpt-0.2.0.dev0/litgpt/data/prepare_slimpajama.py +60 -0
  25. litgpt-0.2.0.dev0/litgpt/data/prepare_starcoder.py +78 -0
  26. litgpt-0.2.0.dev0/litgpt/data/tinyllama.py +91 -0
  27. litgpt-0.2.0.dev0/litgpt/data/tinystories.py +181 -0
  28. litgpt-0.2.0.dev0/litgpt/finetune/__init__.py +0 -0
  29. litgpt-0.2.0.dev0/litgpt/finetune/adapter.py +387 -0
  30. litgpt-0.2.0.dev0/litgpt/finetune/adapter_v2.py +387 -0
  31. litgpt-0.2.0.dev0/litgpt/finetune/full.py +362 -0
  32. litgpt-0.2.0.dev0/litgpt/finetune/lora.py +418 -0
  33. litgpt-0.2.0.dev0/litgpt/generate/__init__.py +0 -0
  34. litgpt-0.2.0.dev0/litgpt/generate/adapter.py +117 -0
  35. litgpt-0.2.0.dev0/litgpt/generate/adapter_v2.py +117 -0
  36. litgpt-0.2.0.dev0/litgpt/generate/base.py +195 -0
  37. litgpt-0.2.0.dev0/litgpt/generate/full.py +113 -0
  38. litgpt-0.2.0.dev0/litgpt/generate/sequentially.py +226 -0
  39. litgpt-0.2.0.dev0/litgpt/generate/tp.py +220 -0
  40. {litgpt-0.1.0.dev1/lit_gpt → litgpt-0.2.0.dev0/litgpt}/lora.py +54 -54
  41. {litgpt-0.1.0.dev1/lit_gpt → litgpt-0.2.0.dev0/litgpt}/model.py +36 -3
  42. litgpt-0.2.0.dev0/litgpt/pretrain.py +430 -0
  43. litgpt-0.2.0.dev0/litgpt/prompts.py +358 -0
  44. litgpt-0.2.0.dev0/litgpt/scripts/__init__.py +0 -0
  45. litgpt-0.2.0.dev0/litgpt/scripts/convert_hf_checkpoint.py +348 -0
  46. litgpt-0.2.0.dev0/litgpt/scripts/convert_lit_checkpoint.py +271 -0
  47. litgpt-0.2.0.dev0/litgpt/scripts/convert_pretrained_checkpoint.py +52 -0
  48. litgpt-0.2.0.dev0/litgpt/scripts/download.py +134 -0
  49. litgpt-0.2.0.dev0/litgpt/scripts/merge_lora.py +85 -0
  50. {litgpt-0.1.0.dev1/lit_gpt → litgpt-0.2.0.dev0/litgpt}/utils.py +85 -11
  51. litgpt-0.2.0.dev0/litgpt.egg-info/PKG-INFO +639 -0
  52. litgpt-0.2.0.dev0/litgpt.egg-info/SOURCES.txt +82 -0
  53. litgpt-0.2.0.dev0/litgpt.egg-info/entry_points.txt +2 -0
  54. litgpt-0.2.0.dev0/litgpt.egg-info/requires.txt +25 -0
  55. litgpt-0.2.0.dev0/litgpt.egg-info/top_level.txt +1 -0
  56. litgpt-0.2.0.dev0/pyproject.toml +66 -0
  57. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_adapter.py +53 -46
  58. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_adapter_v2.py +59 -53
  59. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_chat.py +28 -17
  60. litgpt-0.2.0.dev0/tests/test_ci.py +9 -0
  61. litgpt-0.2.0.dev0/tests/test_cli.py +62 -0
  62. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_config.py +14 -50
  63. litgpt-0.2.0.dev0/tests/test_config_hub.py +55 -0
  64. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_convert_hf_checkpoint.py +7 -7
  65. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_convert_lit_checkpoint.py +41 -37
  66. litgpt-0.2.0.dev0/tests/test_convert_pretrained_checkpoint.py +28 -0
  67. litgpt-0.2.0.dev0/tests/test_full.py +70 -0
  68. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_generate.py +16 -11
  69. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_generate_adapter.py +13 -8
  70. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_generate_sequentially.py +21 -16
  71. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_generate_tp.py +16 -11
  72. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_lm_eval_harness.py +6 -6
  73. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_lora.py +132 -114
  74. litgpt-0.2.0.dev0/tests/test_merge_lora.py +88 -0
  75. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_model.py +43 -29
  76. litgpt-0.2.0.dev0/tests/test_pretrain.py +104 -0
  77. litgpt-0.2.0.dev0/tests/test_prompts.py +117 -0
  78. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_rope.py +1 -1
  79. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_tokenizer.py +3 -3
  80. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/tests/test_utils.py +113 -17
  81. litgpt-0.1.0.dev1/PKG-INFO +0 -284
  82. litgpt-0.1.0.dev1/README.md +0 -273
  83. litgpt-0.1.0.dev1/lit_gpt/packed_dataset.py +0 -239
  84. litgpt-0.1.0.dev1/lit_gpt/rmsnorm.py +0 -34
  85. litgpt-0.1.0.dev1/litgpt.egg-info/PKG-INFO +0 -284
  86. litgpt-0.1.0.dev1/litgpt.egg-info/SOURCES.txt +0 -44
  87. litgpt-0.1.0.dev1/litgpt.egg-info/requires.txt +0 -2
  88. litgpt-0.1.0.dev1/litgpt.egg-info/top_level.txt +0 -1
  89. litgpt-0.1.0.dev1/setup.py +0 -25
  90. litgpt-0.1.0.dev1/tests/test_ci.py +0 -19
  91. litgpt-0.1.0.dev1/tests/test_convert_pretrained_checkpoint.py +0 -33
  92. litgpt-0.1.0.dev1/tests/test_full.py +0 -57
  93. litgpt-0.1.0.dev1/tests/test_generate_lora.py +0 -59
  94. litgpt-0.1.0.dev1/tests/test_merge_lora.py +0 -37
  95. litgpt-0.1.0.dev1/tests/test_packed_dataset.py +0 -207
  96. litgpt-0.1.0.dev1/tests/test_prepare_csv.py +0 -59
  97. litgpt-0.1.0.dev1/tests/test_prepare_redpajama.py +0 -132
  98. litgpt-0.1.0.dev1/tests/test_pretrain_tinyllama.py +0 -51
  99. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/LICENSE +0 -0
  100. {litgpt-0.1.0.dev1/lit_gpt → litgpt-0.2.0.dev0/litgpt}/tokenizer.py +0 -0
  101. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/litgpt.egg-info/dependency_links.txt +0 -0
  102. {litgpt-0.1.0.dev1 → litgpt-0.2.0.dev0}/setup.cfg +0 -0
@@ -0,0 +1,639 @@
1
+ Metadata-Version: 2.1
2
+ Name: litgpt
3
+ Version: 0.2.0.dev0
4
+ Summary: Hackable implementation of state-of-the-art open-source LLMs
5
+ Author-email: Lightning AI <contact@lightning.ai>
6
+ License: Apache License
7
+ Version 2.0, January 2004
8
+ http://www.apache.org/licenses/
9
+
10
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
11
+
12
+ 1. Definitions.
13
+
14
+ "License" shall mean the terms and conditions for use, reproduction,
15
+ and distribution as defined by Sections 1 through 9 of this document.
16
+
17
+ "Licensor" shall mean the copyright owner or entity authorized by
18
+ the copyright owner that is granting the License.
19
+
20
+ "Legal Entity" shall mean the union of the acting entity and all
21
+ other entities that control, are controlled by, or are under common
22
+ control with that entity. For the purposes of this definition,
23
+ "control" means (i) the power, direct or indirect, to cause the
24
+ direction or management of such entity, whether by contract or
25
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
26
+ outstanding shares, or (iii) beneficial ownership of such entity.
27
+
28
+ "You" (or "Your") shall mean an individual or Legal Entity
29
+ exercising permissions granted by this License.
30
+
31
+ "Source" form shall mean the preferred form for making modifications,
32
+ including but not limited to software source code, documentation
33
+ source, and configuration files.
34
+
35
+ "Object" form shall mean any form resulting from mechanical
36
+ transformation or translation of a Source form, including but
37
+ not limited to compiled object code, generated documentation,
38
+ and conversions to other media types.
39
+
40
+ "Work" shall mean the work of authorship, whether in Source or
41
+ Object form, made available under the License, as indicated by a
42
+ copyright notice that is included in or attached to the work
43
+ (an example is provided in the Appendix below).
44
+
45
+ "Derivative Works" shall mean any work, whether in Source or Object
46
+ form, that is based on (or derived from) the Work and for which the
47
+ editorial revisions, annotations, elaborations, or other modifications
48
+ represent, as a whole, an original work of authorship. For the purposes
49
+ of this License, Derivative Works shall not include works that remain
50
+ separable from, or merely link (or bind by name) to the interfaces of,
51
+ the Work and Derivative Works thereof.
52
+
53
+ "Contribution" shall mean any work of authorship, including
54
+ the original version of the Work and any modifications or additions
55
+ to that Work or Derivative Works thereof, that is intentionally
56
+ submitted to Licensor for inclusion in the Work by the copyright owner
57
+ or by an individual or Legal Entity authorized to submit on behalf of
58
+ the copyright owner. For the purposes of this definition, "submitted"
59
+ means any form of electronic, verbal, or written communication sent
60
+ to the Licensor or its representatives, including but not limited to
61
+ communication on electronic mailing lists, source code control systems,
62
+ and issue tracking systems that are managed by, or on behalf of, the
63
+ Licensor for the purpose of discussing and improving the Work, but
64
+ excluding communication that is conspicuously marked or otherwise
65
+ designated in writing by the copyright owner as "Not a Contribution."
66
+
67
+ "Contributor" shall mean Licensor and any individual or Legal Entity
68
+ on behalf of whom a Contribution has been received by Licensor and
69
+ subsequently incorporated within the Work.
70
+
71
+ 2. Grant of Copyright License. Subject to the terms and conditions of
72
+ this License, each Contributor hereby grants to You a perpetual,
73
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
74
+ copyright license to reproduce, prepare Derivative Works of,
75
+ publicly display, publicly perform, sublicense, and distribute the
76
+ Work and such Derivative Works in Source or Object form.
77
+
78
+ 3. Grant of Patent License. Subject to the terms and conditions of
79
+ this License, each Contributor hereby grants to You a perpetual,
80
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
81
+ (except as stated in this section) patent license to make, have made,
82
+ use, offer to sell, sell, import, and otherwise transfer the Work,
83
+ where such license applies only to those patent claims licensable
84
+ by such Contributor that are necessarily infringed by their
85
+ Contribution(s) alone or by combination of their Contribution(s)
86
+ with the Work to which such Contribution(s) was submitted. If You
87
+ institute patent litigation against any entity (including a
88
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
89
+ or a Contribution incorporated within the Work constitutes direct
90
+ or contributory patent infringement, then any patent licenses
91
+ granted to You under this License for that Work shall terminate
92
+ as of the date such litigation is filed.
93
+
94
+ 4. Redistribution. You may reproduce and distribute copies of the
95
+ Work or Derivative Works thereof in any medium, with or without
96
+ modifications, and in Source or Object form, provided that You
97
+ meet the following conditions:
98
+
99
+ (a) You must give any other recipients of the Work or
100
+ Derivative Works a copy of this License; and
101
+
102
+ (b) You must cause any modified files to carry prominent notices
103
+ stating that You changed the files; and
104
+
105
+ (c) You must retain, in the Source form of any Derivative Works
106
+ that You distribute, all copyright, patent, trademark, and
107
+ attribution notices from the Source form of the Work,
108
+ excluding those notices that do not pertain to any part of
109
+ the Derivative Works; and
110
+
111
+ (d) If the Work includes a "NOTICE" text file as part of its
112
+ distribution, then any Derivative Works that You distribute must
113
+ include a readable copy of the attribution notices contained
114
+ within such NOTICE file, excluding those notices that do not
115
+ pertain to any part of the Derivative Works, in at least one
116
+ of the following places: within a NOTICE text file distributed
117
+ as part of the Derivative Works; within the Source form or
118
+ documentation, if provided along with the Derivative Works; or,
119
+ within a display generated by the Derivative Works, if and
120
+ wherever such third-party notices normally appear. The contents
121
+ of the NOTICE file are for informational purposes only and
122
+ do not modify the License. You may add Your own attribution
123
+ notices within Derivative Works that You distribute, alongside
124
+ or as an addendum to the NOTICE text from the Work, provided
125
+ that such additional attribution notices cannot be construed
126
+ as modifying the License.
127
+
128
+ You may add Your own copyright statement to Your modifications and
129
+ may provide additional or different license terms and conditions
130
+ for use, reproduction, or distribution of Your modifications, or
131
+ for any such Derivative Works as a whole, provided Your use,
132
+ reproduction, and distribution of the Work otherwise complies with
133
+ the conditions stated in this License.
134
+
135
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
136
+ any Contribution intentionally submitted for inclusion in the Work
137
+ by You to the Licensor shall be under the terms and conditions of
138
+ this License, without any additional terms or conditions.
139
+ Notwithstanding the above, nothing herein shall supersede or modify
140
+ the terms of any separate license agreement you may have executed
141
+ with Licensor regarding such Contributions.
142
+
143
+ 6. Trademarks. This License does not grant permission to use the trade
144
+ names, trademarks, service marks, or product names of the Licensor,
145
+ except as required for reasonable and customary use in describing the
146
+ origin of the Work and reproducing the content of the NOTICE file.
147
+
148
+ 7. Disclaimer of Warranty. Unless required by applicable law or
149
+ agreed to in writing, Licensor provides the Work (and each
150
+ Contributor provides its Contributions) on an "AS IS" BASIS,
151
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
152
+ implied, including, without limitation, any warranties or conditions
153
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
154
+ PARTICULAR PURPOSE. You are solely responsible for determining the
155
+ appropriateness of using or redistributing the Work and assume any
156
+ risks associated with Your exercise of permissions under this License.
157
+
158
+ 8. Limitation of Liability. In no event and under no legal theory,
159
+ whether in tort (including negligence), contract, or otherwise,
160
+ unless required by applicable law (such as deliberate and grossly
161
+ negligent acts) or agreed to in writing, shall any Contributor be
162
+ liable to You for damages, including any direct, indirect, special,
163
+ incidental, or consequential damages of any character arising as a
164
+ result of this License or out of the use or inability to use the
165
+ Work (including but not limited to damages for loss of goodwill,
166
+ work stoppage, computer failure or malfunction, or any and all
167
+ other commercial damages or losses), even if such Contributor
168
+ has been advised of the possibility of such damages.
169
+
170
+ 9. Accepting Warranty or Additional Liability. While redistributing
171
+ the Work or Derivative Works thereof, You may choose to offer,
172
+ and charge a fee for, acceptance of support, warranty, indemnity,
173
+ or other liability obligations and/or rights consistent with this
174
+ License. However, in accepting such obligations, You may act only
175
+ on Your own behalf and on Your sole responsibility, not on behalf
176
+ of any other Contributor, and only if You agree to indemnify,
177
+ defend, and hold each Contributor harmless for any liability
178
+ incurred by, or claims asserted against, such Contributor by reason
179
+ of your accepting any such warranty or additional liability.
180
+
181
+ END OF TERMS AND CONDITIONS
182
+
183
+ APPENDIX: How to apply the Apache License to your work.
184
+
185
+ To apply the Apache License to your work, attach the following
186
+ boilerplate notice, with the fields enclosed by brackets "[]"
187
+ replaced with your own identifying information. (Don't include
188
+ the brackets!) The text should be enclosed in the appropriate
189
+ comment syntax for the file format. We also recommend that a
190
+ file or class name and description of purpose be included on the
191
+ same "printed page" as the copyright notice for easier
192
+ identification within third-party archives.
193
+
194
+ Copyright [2023] Lightning AI
195
+
196
+ Licensed under the Apache License, Version 2.0 (the "License");
197
+ you may not use this file except in compliance with the License.
198
+ You may obtain a copy of the License at
199
+
200
+ http://www.apache.org/licenses/LICENSE-2.0
201
+
202
+ Unless required by applicable law or agreed to in writing, software
203
+ distributed under the License is distributed on an "AS IS" BASIS,
204
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
205
+ See the License for the specific language governing permissions and
206
+ limitations under the License.
207
+
208
+ Project-URL: homepage, https://github.com/lightning-AI/litgpt
209
+ Project-URL: documentation, https://github.com/lightning-AI/litgpt/tutorials
210
+ Description-Content-Type: text/markdown
211
+ License-File: LICENSE
212
+ Requires-Dist: torch>=2.2.0
213
+ Requires-Dist: lightning==2.3.0.dev20240318
214
+ Requires-Dist: jsonargparse[signatures]>=4.27.6
215
+ Provides-Extra: test
216
+ Requires-Dist: pytest; extra == "test"
217
+ Requires-Dist: pytest-rerunfailures; extra == "test"
218
+ Requires-Dist: pytest-timeout; extra == "test"
219
+ Requires-Dist: transformers>=4.38.0; extra == "test"
220
+ Requires-Dist: einops; extra == "test"
221
+ Requires-Dist: protobuf; extra == "test"
222
+ Provides-Extra: all
223
+ Requires-Dist: bitsandbytes==0.42.0; extra == "all"
224
+ Requires-Dist: sentencepiece; extra == "all"
225
+ Requires-Dist: tokenizers; extra == "all"
226
+ Requires-Dist: datasets; extra == "all"
227
+ Requires-Dist: requests; extra == "all"
228
+ Requires-Dist: litdata; extra == "all"
229
+ Requires-Dist: zstandard; extra == "all"
230
+ Requires-Dist: pandas; extra == "all"
231
+ Requires-Dist: pyarrow; extra == "all"
232
+ Requires-Dist: tensorboard; extra == "all"
233
+ Requires-Dist: torchmetrics; extra == "all"
234
+ Requires-Dist: huggingface_hub[hf_transfer]>=0.21.0; extra == "all"
235
+
236
+ <div align="center">
237
+ <img src="https://pl-public-data.s3.amazonaws.com/assets_lightning/LitStableLM_Badge.png" alt="LitGPT" width="128"/>
238
+
239
+ # ⚡ LitGPT
240
+
241
+ <!--
242
+ <p align="center">
243
+ <a href="https://www.lightning.ai/">Lightning.ai</a> •
244
+ <a href="https://lightning.ai/docs/pytorch/stable/">PyTorch Lightning</a> •
245
+ <a href="https://lightning.ai/docs/fabric/stable/">Fabric</a>
246
+ </p>
247
+ -->
248
+
249
+ ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pytorch-lightning)
250
+ ![cpu-tests](https://github.com/lightning-AI/lit-stablelm/actions/workflows/cpu-tests.yml/badge.svg) [![license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/Lightning-AI/lit-stablelm/blob/master/LICENSE) [![Discord](https://img.shields.io/discord/1077906959069626439?style=plastic)](https://discord.gg/VptPCZkGNa)
251
+
252
+ </div>
253
+
254
+ &nbsp;
255
+
256
+ ⚡ LitGPT is a hackable [implementation](litgpt/model.py) of state-of-the-art open-source large language models released under the **Apache 2.0 license**.
257
+
258
+ &nbsp;
259
+ ## LitGPT supports
260
+
261
+ ✅ &nbsp;[The latest model weights](tutorials/download_model_weights.md): Gemma, Mistral, Mixtral, Phi 2, Llama 2, Falcon, CodeLlama, and [many more](tutorials/download_model_weights.md).
262
+
263
+ ✅ &nbsp;Optimized and efficient code: Flash Attention v2, multi-GPU support via fully-sharded data parallelism, [optional CPU offloading](tutorials/oom.md#do-sharding-across-multiple-gpus), and [TPU and XLA support](./xla).
264
+
265
+ ✅ &nbsp;[Pretraining](tutorials/pretraining.md), [finetuning](tutorials/finetune.md), and [inference](tutorials/inference.md) in various precision settings: FP32, FP16, BF16, and FP16/FP32 mixed.
266
+
267
+ ✅ &nbsp;[Configuration files](config_hub) for great out-of-the-box performance.
268
+
269
+ ✅ &nbsp;Efficient finetuning: [LoRA](tutorials/finetune_lora.md), [QLoRA](tutorials/finetune_lora.md), [Adapter](tutorials/finetune_adapter.md), and [Adapter v2](tutorials/finetune_adapter.md).
270
+
271
+ ✅ &nbsp;[Quantization](tutorials/quantize.md): 4-bit floats, 8-bit integers, and double quantization.
272
+
273
+ ✅ &nbsp;[Exporting](https://github.com/Lightning-AI/litgpt/blob/wip/tutorials/convert_lit_models.md) to other popular model weight formats.
274
+
275
+ ✅ &nbsp;Many popular datasets for [pretraining](tutorials/pretrain_tinyllama.md) and [finetuning](tutorials/prepare_dataset.md), and [support for custom datasets](tutorials/prepare_dataset.md#preparing-custom-datasets-for-instruction-finetuning).
276
+
277
+ ✅ &nbsp;Readable and easy-to-modify code to experiment with the latest research ideas.
278
+
279
+
280
+ &nbsp;
281
+ <br>
282
+ &nbsp;
283
+
284
+ ## Project templates
285
+
286
+ The following [Lightning Studio](https://lightning.ai/lightning-ai/studios) templates provide LitGPT tutorials and projects in reproducible environments with multi-GPU and multi-node support:
287
+
288
+
289
+ | | |
290
+ |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
291
+ | <p align="left">[Prepare the TinyLlama 1T token dataset](https://lightning.ai/lightning-ai/studios/prepare-the-tinyllama-1t-token-dataset) <br> [<img src="https://pl-public-data.s3.amazonaws.com/assets_litgpt/readme/3.webp" width="300"></p>](https://lightning.ai/lightning-ai/studios/prepare-the-tinyllama-1t-token-dataset) | [Pretrain LLMs - TinyLlama 1.1B](https://lightning.ai/lightning-ai/studios/pretrain-llms-tinyllama-1-1b) <br> <p align="left">[<img src="https://pl-public-data.s3.amazonaws.com/assets_litgpt/readme/4.webp" width="300"></p>](https://lightning.ai/lightning-ai/studios/pretrain-llms-tinyllama-1-1b) |
292
+ | [Continued Pretraining with TinyLlama 1.1B](https://lightning.ai/lightning-ai/studios/continued-pretraining-with-tinyllama-1-1b) <br> <p align="left">[<img src="https://pl-public-data.s3.amazonaws.com/assets_litgpt/readme/1.webp" width="300"></p>](https://lightning.ai/lightning-ai/studios/continued-pretraining-with-tinyllama-1-1b) | [Instruction finetuning - TinyLlama 1.1B LLM](https://lightning.ai/lightning-ai/studios/instruction-finetuning-tinyllama-1-1b-llm) <br> <p align="left">[<img src="https://pl-public-data.s3.amazonaws.com/assets_litgpt/readme/2.webp" width="300"></p>](https://lightning.ai/lightning-ai/studios/instruction-finetuning-tinyllama-1-1b-llm) |
293
+ | | |
294
+
295
+
296
+
297
+
298
+
299
+ &nbsp;
300
+ <br>
301
+ &nbsp;
302
+
303
+
304
+
305
+ ## Installing LitGPT
306
+
307
+ You can install LitGPT with all dependencies (including CLI, quantization, tokenizers for all models, etc.) using the following pip command:
308
+
309
+ ```bash
310
+ pip install 'litgpt[all] @ git+https://github.com/Lightning-AI/litgpt'
311
+ ```
312
+
313
+ Alternatively, can install litgpt from a cloned GitHub repository:
314
+
315
+ ```bash
316
+ git clone https://github.com/Lightning-AI/litgpt
317
+ cd litgpt
318
+ pip install -e '.[all]'
319
+ ```
320
+
321
+
322
+ &nbsp;
323
+
324
+ ## Using LitGPT
325
+
326
+
327
+ Below is a minimal example to get started with the LitGPT command line interface (CLI), illustrating how to download and use a model:
328
+
329
+
330
+ ```bash
331
+ # 1) Download a pretrained model
332
+ litgpt download --repo_id mistralai/Mistral-7B-Instruct-v0.2
333
+
334
+ # 2) Chat with the model
335
+ litgpt chat \
336
+ --checkpoint_dir checkpoints/mistralai/Mistral-7B-Instruct-v0.2
337
+
338
+ >> Prompt: What do Llamas eat?
339
+ ```
340
+
341
+ For more information, refer to the [download](tutorials/download_model_weights.md) and [inference](tutorials/inference.md) tutorials.
342
+
343
+
344
+ &nbsp;
345
+ ## Finetuning and pretraining
346
+
347
+ LitGPT supports [pretraining](tutorials/pretrain_tinyllama.md) and [finetuning](tutorials/finetune.md) to optimize models on excisting or custom datasets. Below is an example showing how to finetune a model with LoRA:
348
+
349
+ ```bash
350
+ # 1) Download a pretrained model
351
+ litgpt download --repo_id microsoft/phi-2
352
+
353
+ # 2) Finetune the model
354
+ litgpt finetune lora \
355
+ --checkpoint_dir checkpoints/microsoft/phi-2 \
356
+ --data Alpaca2k \
357
+ --out_dir out/phi-2-lora
358
+
359
+ # 3) Chat with the model
360
+ litgpt chat \
361
+ --checkpoint_dir out/phi-2-lora/final
362
+ ```
363
+
364
+ &nbsp;
365
+ ## Configuration files for enhanced performance
366
+
367
+ LitGPT also allows users to use configuration files in YAML format instead of specifying settings via the command line interface and comes with a set of model-specific defaults for good out-of-the-box performance:
368
+
369
+
370
+ ```bash
371
+ litgpt finetune lora \
372
+ --config https://github.com/Lightning-AI/litgpt/blob/wip/config_hub/finetune/llama-2-7b/lora.yaml
373
+ ```
374
+
375
+ For added convenience, you can also manually override config file setting via the CLI:
376
+
377
+
378
+ ```bash
379
+ litgpt finetune lora \
380
+ --config https://raw.githubusercontent.com/Lightning-AI/litgpt/main/config_hub/finetune/llama-2-7b/lora.yaml \
381
+ --lora_r 4
382
+ ```
383
+
384
+ You can browse the available configuration files [here](https://github.com/Lightning-AI/litgpt/tree/main/config_hub).
385
+
386
+ &nbsp;
387
+
388
+ > [!TIP]
389
+ > **Run large models on smaller consumer devices:**
390
+ > We support 4-bit quantization (as in QLoRA), (bnb.nf4, bnb.nf4-dq, bnb.fp4, bnb.fp4-dq) and 8-bit quantization (bnb.int8) for inference by following [this guide](tutorials/quantize.md).
391
+
392
+
393
+ &nbsp;
394
+ <br>
395
+ &nbsp;
396
+
397
+ ## Customization
398
+
399
+ LitGPT supports rich and customizable [config files](config_hub) to tailor the LLM training to your dataset and hardware needs. Shown below is a configuration file for LoRA finetuning:
400
+
401
+ ```yaml
402
+ # The path to the base model's checkpoint directory to load for finetuning. (type: <class 'Path'>, default: checkpoints/stabilityai/stablelm-base-alpha-3b)
403
+ checkpoint_dir: checkpoints/meta-llama/Llama-2-7b-hf
404
+
405
+ # Directory in which to save checkpoints and logs. (type: <class 'Path'>, default: out/lora)
406
+ out_dir: out/finetune/qlora-llama2-7b
407
+
408
+ # The precision to use for finetuning. Possible choices: "bf16-true", "bf16-mixed", "32-true". (type: Optional[str], default: null)
409
+ precision: bf16-true
410
+
411
+ # If set, quantize the model with this algorithm. See ``tutorials/quantize.md`` for more information. (type: Optional[Literal['nf4', 'nf4-dq', 'fp4', 'fp4-dq', 'int8-training']], default: null)
412
+ quantize: bnb.nf4
413
+
414
+ # How many devices/GPUs to use. (type: Union[int, str], default: 1)
415
+ devices: 1
416
+
417
+ # The LoRA rank. (type: int, default: 8)
418
+ lora_r: 32
419
+
420
+ # The LoRA alpha. (type: int, default: 16)
421
+ lora_alpha: 16
422
+
423
+ # The LoRA dropout value. (type: float, default: 0.05)
424
+ lora_dropout: 0.05
425
+
426
+ # Whether to apply LoRA to the query weights in attention. (type: bool, default: True)
427
+ lora_query: true
428
+
429
+ # Whether to apply LoRA to the key weights in attention. (type: bool, default: False)
430
+ lora_key: false
431
+
432
+ # Whether to apply LoRA to the value weights in attention. (type: bool, default: True)
433
+ lora_value: true
434
+
435
+ # Whether to apply LoRA to the output projection in the attention block. (type: bool, default: False)
436
+ lora_projection: false
437
+
438
+ # Whether to apply LoRA to the weights of the MLP in the attention block. (type: bool, default: False)
439
+ lora_mlp: false
440
+
441
+ # Whether to apply LoRA to output head in GPT. (type: bool, default: False)
442
+ lora_head: false
443
+
444
+ # Data-related arguments. If not provided, the default is ``litgpt.data.Alpaca``.
445
+ data:
446
+ class_path: litgpt.data.Alpaca2k
447
+ init_args:
448
+ mask_prompt: false
449
+ val_split_fraction: 0.05
450
+ prompt_style: alpaca
451
+ ignore_index: -100
452
+ seed: 42
453
+ num_workers: 4
454
+ download_dir: data/alpaca2k
455
+
456
+ # Training-related arguments. See ``litgpt.args.TrainArgs`` for details
457
+ train:
458
+
459
+ # Number of optimizer steps between saving checkpoints (type: Optional[int], default: 1000)
460
+ save_interval: 200
461
+
462
+ # Number of iterations between logging calls (type: int, default: 1)
463
+ log_interval: 1
464
+
465
+ # Number of samples between optimizer steps across data-parallel ranks (type: int, default: 128)
466
+ global_batch_size: 8
467
+
468
+ # Number of samples per data-parallel rank (type: int, default: 4)
469
+ micro_batch_size: 2
470
+
471
+ # Number of iterations with learning rate warmup active (type: int, default: 100)
472
+ lr_warmup_steps: 10
473
+
474
+ # Number of epochs to train on (type: Optional[int], default: 5)
475
+ epochs: 4
476
+
477
+ # Total number of tokens to train on (type: Optional[int], default: null)
478
+ max_tokens:
479
+
480
+ # Limits the number of optimizer steps to run (type: Optional[int], default: null)
481
+ max_steps:
482
+
483
+ # Limits the length of samples (type: Optional[int], default: null)
484
+ max_seq_length: 512
485
+
486
+ # Whether to tie the embedding weights with the language modeling head weights (type: Optional[bool], default: null)
487
+ tie_embeddings:
488
+
489
+ # (type: float, default: 0.0003)
490
+ learning_rate: 0.0002
491
+
492
+ # (type: float, default: 0.02)
493
+ weight_decay: 0.0
494
+
495
+ # (type: float, default: 0.9)
496
+ beta1: 0.9
497
+
498
+ # (type: float, default: 0.95)
499
+ beta2: 0.95
500
+
501
+ # (type: Optional[float], default: null)
502
+ max_norm:
503
+
504
+ # (type: float, default: 6e-05)
505
+ min_lr: 6.0e-05
506
+
507
+ # Evaluation-related arguments. See ``litgpt.args.EvalArgs`` for details
508
+ eval:
509
+
510
+ # Number of optimizer steps between evaluation calls (type: int, default: 100)
511
+ interval: 100
512
+
513
+ # Number of tokens to generate (type: Optional[int], default: 100)
514
+ max_new_tokens: 100
515
+
516
+ # Number of iterations (type: int, default: 100)
517
+ max_iters: 100
518
+
519
+ # The name of the logger to send metrics to. (type: Literal['wandb', 'tensorboard', 'csv'], default: csv)
520
+ logger_name: csv
521
+
522
+ # The random seed to use for reproducibility. (type: int, default: 1337)
523
+ seed: 1337
524
+ ```
525
+
526
+
527
+ &nbsp;
528
+
529
+ ## LitGPT design principles
530
+
531
+ This repository follows the main principle of **openness through clarity**.
532
+
533
+ **LitGPT** is:
534
+
535
+ - **Simple:** Single-file implementation without boilerplate.
536
+ - **Correct:** Numerically equivalent to the original model.
537
+ - **Optimized:** Runs fast on consumer hardware or at scale.
538
+ - **Open-source:** No strings attached.
539
+
540
+ Avoiding code duplication is **not** a goal. **Readability** and **hackability** are.
541
+
542
+ &nbsp;
543
+
544
+ ## Get involved!
545
+
546
+ We appreciate your feedback and contributions. If you have feature requests, questions, or want to contribute code or config files, please don't hesitate to use the [GitHub Issue](https://github.com/Lightning-AI/litgpt/issues) tracker.
547
+
548
+ We welcome all individual contributors, regardless of their level of experience or hardware. Your contributions are valuable, and we are excited to see what you can accomplish in this collaborative and supportive environment.
549
+
550
+ &nbsp;
551
+
552
+ > [!TIP]
553
+ > Unsure about contributing? Check out our [How to Contribute to LitGPT](https://lightning.ai/pages/community/tutorial/how-to-contribute-to-litgpt/) guide.
554
+
555
+ If you have general questions about building with LitGPT, please [join our Discord](https://discord.gg/VptPCZkGNa).
556
+
557
+
558
+ &nbsp;
559
+
560
+ ## Tutorials, how-to guides, and docs
561
+
562
+ - Finetuning, incl. LoRA, QLoRA, and Adapters ([tutorials/finetune.md](tutorials/finetune.md))
563
+ - Pretraining ([tutorials/pretrain_tinyllama.md](tutorials/pretrain_tinyllama.md))
564
+ - Model evaluation ([tutorials/evaluation.md](tutorials/evaluation.md))
565
+ - Supported and custom datasets ([tutorials/prepare_dataset.md](tutorials/prepare_dataset.md))
566
+ - Quantization ([tutorials/quantize.md](tutorials/quantize.md))
567
+ - Tips for dealing with out-of-memory (OOM) errors ([tutorials/oom.md](tutorials/oom.md))
568
+
569
+
570
+
571
+
572
+
573
+ &nbsp;
574
+
575
+ ## XLA
576
+
577
+ Lightning AI has partnered with Google to add first-class support for [Cloud TPUs](https://cloud.google.com/tpu) in [Lightning’s frameworks](https://github.com/Lightning-AI/lightning) and LitGPT,
578
+ helping democratize AI for millions of developers and researchers worldwide.
579
+
580
+ Using TPUs with Lightning is as straightforward as changing one line of code.
581
+
582
+ We provide scripts fully optimized for TPUs in the [XLA directory](xla).
583
+
584
+
585
+
586
+ &nbsp;
587
+
588
+ ## Acknowledgements
589
+
590
+ This implementation extends on [Lit-LLaMA](https://github.com/lightning-AI/lit-llama) and [nanoGPT](https://github.com/karpathy/nanoGPT), and it's **powered by [Lightning Fabric](https://lightning.ai/docs/fabric/stable/) ⚡**.
591
+
592
+ - [@karpathy](https://github.com/karpathy) for [nanoGPT](https://github.com/karpathy/nanoGPT)
593
+ - [@EleutherAI](https://github.com/EleutherAI) for [GPT-NeoX](https://github.com/EleutherAI/gpt-neox) and the [Evaluation Harness](https://github.com/EleutherAI/lm-evaluation-harness)
594
+ - [@TimDettmers](https://github.com/TimDettmers) for [bitsandbytes](https://github.com/TimDettmers/bitsandbytes)
595
+ - [@Microsoft](https://github.com/microsoft) for [LoRA](https://github.com/microsoft/LoRA)
596
+ - [@tridao](https://github.com/tridao) for [Flash Attention 2](https://github.com/Dao-AILab/flash-attention)
597
+
598
+
599
+ &nbsp;
600
+
601
+
602
+ ## Community showcase
603
+
604
+ Check out the projects below using and building on LitGPT. If you have a project you'd like to add to this section, please don't hestiate to open a pull request.
605
+
606
+ &nbsp;
607
+
608
+ **🏆 NeurIPS 2023 Large Language Model Efficiency Challenge: 1 LLM + 1 GPU + 1 Day**
609
+
610
+ The LitGPT repository was the official starter kit for the [NeurIPS 2023 LLM Efficiency Challenge](https://llm-efficiency-challenge.github.io), which is a competition focused on finetuning an existing non-instruction tuned LLM for 24 hours on a single GPU.
611
+
612
+ &nbsp;
613
+
614
+ **🦙 TinyLlama: An Open-Source Small Language Model**
615
+
616
+ LitGPT powered the [TinyLlama project](https://github.com/jzhang38/TinyLlama) and [TinyLlama: An Open-Source Small Language Model](https://arxiv.org/abs/2401.02385) research paper.
617
+
618
+
619
+ &nbsp;
620
+
621
+ ## Citation
622
+
623
+ If you use LitGPT in your research, please cite the following work:
624
+
625
+ ```bibtex
626
+ @misc{litgpt-2023,
627
+ author = {Lightning AI},
628
+ title = {LitGPT},
629
+ howpublished = {\url{https://github.com/Lightning-AI/litgpt}},
630
+ year = {2023},
631
+ }
632
+ ```
633
+
634
+ &nbsp;
635
+
636
+ ## License
637
+
638
+ LitGPT is released under the [Apache 2.0](https://github.com/Lightning-AI/litgpt/blob/main/LICENSE) license.
639
+