initial commit
|
After Width: | Height: | Size: 874 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 209 KiB |
|
After Width: | Height: | Size: 277 KiB |
|
After Width: | Height: | Size: 6.8 KiB |
|
After Width: | Height: | Size: 62 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 44 KiB |
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2024 Jay Alammar & Maarten Grootendorst
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -0,0 +1,111 @@
|
||||
# Hands-On Large Language Models CN(ZH)
|
||||
|
||||
> 这是中文版本的 hands-on LLMs
|
||||
|
||||
<a href="https://www.linkedin.com/in/jalammar/"><img src="https://img.shields.io/badge/Follow%20Jay-blue.svg?logo=linkedin"></a>
|
||||
<a href="https://www.linkedin.com/in/mgrootendorst/"><img src="https://img.shields.io/badge/Follow%20Maarten-blue.svg?logo=linkedin"></a>
|
||||
|
||||
|
||||
> 这是中文版本的 hands-on LLMs
|
||||
|
||||
|
||||
Welcome! In this repository you will find the code for all examples throughout the book [Hands-On Large Language Models](https://www.amazon.com/Hands-Large-Language-Models-Understanding/dp/1098150961) written by [Jay Alammar](https://www.linkedin.com/in/jalammar/) and [Maarten Grootendorst](https://www.linkedin.com/in/mgrootendorst/) which we playfully dubbed: <br>
|
||||
|
||||
<p align="center"><b><i>"The Illustrated LLM Book"</i></b></p>
|
||||
|
||||
Through the visually educational nature of this book and with **over 250 custom made figures**, learn the practical tools and concepts you need to use Large Language Models today!
|
||||
|
||||
<a href="https://www.amazon.com/Hands-Large-Language-Models-Understanding/dp/1098150961"><img src="images/book_cover.png" width="50%" height="50%"></a>
|
||||
|
||||
<br>
|
||||
|
||||
The digital version of the book is available on:
|
||||
|
||||
* [Amazon](https://www.amazon.com/Hands-Large-Language-Models-Understanding/dp/1098150961)
|
||||
* [O'Reilly](https://www.oreilly.com/library/view/hands-on-large-language/9781098150952/)
|
||||
* [Kindle](https://www.amazon.com/Hands-Large-Language-Models-Alammar-ebook/dp/B0DGZ46G88/ref=tmm_kin_swatch_0?_encoding=UTF8&qid=&sr=)
|
||||
* [Barnes and Noble](https://www.barnesandnoble.com/w/hands-on-large-language-models-jay-alammar/1145185960)
|
||||
|
||||
Note that the book is sent to the printer and will be released in print format in the coming weeks!
|
||||
|
||||
## Table of Contents
|
||||
|
||||
We advise to run all examples through Google Colab for the easiest setup. Google Colab allows you to use a T4 GPU with 16GB of VRAM for free. All examples were mainly built and tested using Google Colab, so it should be the most stable platform. However, any other cloud provider should work.
|
||||
|
||||
| Chapter | Notebook |
|
||||
|---|---|
|
||||
| Chapter 1: Introduction to Language Models | [](https://colab.research.google.com/github/HandsOnLLM/Hands-On-Large-Language-Models/blob/main/chapter01/Chapter%201%20-%20Introduction%20to%20Language%20Models.ipynb) |
|
||||
| Chapter 2: Tokens and Embeddings | [](https://colab.research.google.com/github/HandsOnLLM/Hands-On-Large-Language-Models/blob/main/chapter02/Chapter%202%20-%20Tokens%20and%20Token%20Embeddings.ipynb) |
|
||||
| Chapter 3: Looking Inside Transformer LLMs | [](https://colab.research.google.com/github/HandsOnLLM/Hands-On-Large-Language-Models/blob/main/chapter03/Chapter%203%20-%20Looking%20Inside%20LLMs.ipynb) |
|
||||
| Chapter 4: Text Classification | [](https://colab.research.google.com/github/HandsOnLLM/Hands-On-Large-Language-Models/blob/main/chapter04/Chapter%204%20-%20Text%20Classification.ipynb) |
|
||||
| Chapter 5: Text Clustering and Topic Modeling | [](https://colab.research.google.com/github/HandsOnLLM/Hands-On-Large-Language-Models/blob/main/chapter05/Chapter%205%20-%20Text%20Clustering%20and%20Topic%20Modeling.ipynb) |
|
||||
| Chapter 6: Prompt Engineering | [](https://colab.research.google.com/github/HandsOnLLM/Hands-On-Large-Language-Models/blob/main/chapter06/Chapter%206%20-%20Prompt%20Engineering.ipynb) |
|
||||
| Chapter 7: Advanced Text Generation Techniques and Tools | [](https://colab.research.google.com/github/HandsOnLLM/Hands-On-Large-Language-Models/blob/main/chapter07/Chapter%207%20-%20Advanced%20Text%20Generation%20Techniques%20and%20Tools.ipynb) |
|
||||
| Chapter 8: Semantic Search and Retrieval-Augmented Generation | [](https://colab.research.google.com/github/HandsOnLLM/Hands-On-Large-Language-Models/blob/main/chapter08/Chapter%208%20-%20Semantic%20Search.ipynb) |
|
||||
| Chapter 9: Multimodal Large Language Models | [](https://colab.research.google.com/github/HandsOnLLM/Hands-On-Large-Language-Models/blob/main/chapter09/Chapter%209%20-%20Multimodal%20Large%20Language%20Models.ipynb) |
|
||||
| Chapter 10: Creating Text Embedding Models | [](https://colab.research.google.com/github/HandsOnLLM/Hands-On-Large-Language-Models/blob/main/chapter10/Chapter%2010%20-%20Creating%20Text%20Embedding%20Models.ipynb) |
|
||||
| Chapter 11: Fine-tuning Representation Models for Classification | [](https://colab.research.google.com/github/HandsOnLLM/Hands-On-Large-Language-Models/blob/main/chapter11/Chapter%2011%20-%20Fine-Tuning%20BERT.ipynb) |
|
||||
| Chapter 12: Fine-tuning Generation Models | [](https://colab.research.google.com/github/HandsOnLLM/Hands-On-Large-Language-Models/blob/main/chapter12/Chapter%2012%20-%20Fine-tuning%20Generation%20Models.ipynb) |
|
||||
|
||||
> [!TIP]
|
||||
> You can check the [setup](.setup/) folder for a quick-start guide to install all packages locally and you can check the [conda](.setup/conda/) folder for a complete guide on how to setup your environment, including conda and PyTorch installation.
|
||||
> Note that the depending on your OS, Python version, and dependencies your results might be slightly differ. However, they
|
||||
> should this be similar to the examples in the book.
|
||||
|
||||
|
||||
## Reviews
|
||||
|
||||
> "*Jay and Maarten have continued their tradition of providing beautifully illustrated and insightful descriptions of complex topics in their new book. Bolstered with working code, timelines, and references to key papers, their book is a valuable resource for anyone looking to understand the main techniques behind how Large Language Models are built.*"
|
||||
>
|
||||
> **Andrew Ng** - founder of [DeepLearning.AI](https://www.deeplearning.ai/)
|
||||
|
||||
---
|
||||
|
||||
> "*This is an exceptional guide to the world of language models and their practical applications in industry. Its highly-visual coverage of generative, representational, and retrieval applications of language models empowers readers to quickly understand, use, and refine LLMs. Highly recommended!*"
|
||||
>
|
||||
> **Nils Reimers** - Director of Machine Learning at Cohere | creator of [sentence-transformers](https://github.com/UKPLab/sentence-transformers)
|
||||
|
||||
---
|
||||
|
||||
> "*I can’t think of another book that is more important to read right now. On every single page, I learned something that is critical to success in this era of language models.*"
|
||||
>
|
||||
> **Josh Starmer** - [StatQuest](https://www.youtube.com/channel/UCtYLUTtgS3k1Fg4y5tAhLbw)
|
||||
|
||||
---
|
||||
|
||||
> "*If you’re looking to get up to speed in everything regarding LLMs, look no further! In this wonderful book, Jay and Maarten will take you from zero to expert in the history and latest advances in large language models. With very intuitive explanations, great real-life examples, clear illustrations, and comprehensive code labs, this book lifts the curtain on the complexities of transformer models, tokenizers, semantic search, RAG, and many other cutting-edge technologies. A must read for anyone interested in the latest AI technology!*"
|
||||
>
|
||||
> **Luis Serrano, PhD** - Founder and CEO of [Serrano Academy](https://www.youtube.com/@SerranoAcademy)
|
||||
|
||||
---
|
||||
|
||||
> "*Hands-On Large Language Models brings clarity and practical examples to cut through the hype of AI. It provides a wealth of great diagrams and visual aids to supplement the clear explanations. The worked examples and code make concrete what other books leave abstract. The book starts with simple introductory beginnings, and steadily builds in scope. By the final chapters, you will be fine-tuning and building your own large language models with confidence.*"
|
||||
>
|
||||
> **Leland McInnes** - Researcher at the Tutte Institute for Mathematics and Computing | creator of [UMAP](https://github.com/lmcinnes/umap) and [HDBSCAN](https://github.com/scikit-learn-contrib/hdbscan)
|
||||
|
||||
---
|
||||
|
||||
## Additional Resources
|
||||
|
||||
We attempted to put as much information into the book without it being overwhelming. However, even with a 400-page book there is still much to discover! If you are interested in similar illustrated/visual guides we created, these might be of interest to you:
|
||||
|
||||
| [A Visual Guide to Mamba](https://newsletter.maartengrootendorst.com/p/a-visual-guide-to-mamba-and-state) | [A Visual Guide to Quantization](https://newsletter.maartengrootendorst.com/p/a-visual-guide-to-quantization) | [The Illustrated Stable Diffusion](https://jalammar.github.io/illustrated-stable-diffusion/) |
|
||||
:-------------------------:|:-------------------------:|:-------------------------:
|
||||
 |  | 
|
||||
|
||||
|
||||
## Citation
|
||||
|
||||
Please consider citing the book if you consider it useful for your research:
|
||||
|
||||
```
|
||||
@book{hands-on-llms-book,
|
||||
author = {Jay Alammar and Maarten Grootendorst},
|
||||
title = {Hands-On Large Language Models},
|
||||
publisher = {O'Reilly},
|
||||
year = {2024},
|
||||
isbn = {978-1098150969},
|
||||
url = {https://www.oreilly.com/library/view/hands-on-large-language/9781098150952/},
|
||||
github = {https://github.com/HandsOnLLM/Hands-On-Large-Language-Models}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,507 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "e25cd1d1-8c57-42ab-bb2c-4a70617361c4",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T07:36:37.572016Z",
|
||||
"iopub.status.busy": "2024-10-11T07:36:37.571650Z",
|
||||
"iopub.status.idle": "2024-10-11T07:36:37.576090Z",
|
||||
"shell.execute_reply": "2024-10-11T07:36:37.575614Z",
|
||||
"shell.execute_reply.started": "2024-10-11T07:36:37.571982Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
"# 第一章 -- 认识LLM\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"id": "7c8f86ef-c637-488f-923a-95fe515a60a1",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T07:56:03.928487Z",
|
||||
"iopub.status.busy": "2024-10-11T07:56:03.928036Z",
|
||||
"iopub.status.idle": "2024-10-11T07:56:04.366237Z",
|
||||
"shell.execute_reply": "2024-10-11T07:56:04.365536Z",
|
||||
"shell.execute_reply.started": "2024-10-11T07:56:03.928450Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
|
||||
"To disable this warning, you can either:\n",
|
||||
"\t- Avoid using `tokenizers` before the fork if possible\n",
|
||||
"\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Fri Oct 11 07:56:04 2024 \n",
|
||||
"+---------------------------------------------------------------------------------------+\n",
|
||||
"| NVIDIA-SMI 535.129.03 Driver Version: 535.129.03 CUDA Version: 12.2 |\n",
|
||||
"|-----------------------------------------+----------------------+----------------------+\n",
|
||||
"| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |\n",
|
||||
"| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |\n",
|
||||
"| | | MIG M. |\n",
|
||||
"|=========================================+======================+======================|\n",
|
||||
"| 0 NVIDIA GeForce RTX 4090 On | 00000000:A1:00.0 Off | Off |\n",
|
||||
"| 30% 30C P8 17W / 450W | 2854MiB / 24564MiB | 0% Default |\n",
|
||||
"| | | N/A |\n",
|
||||
"+-----------------------------------------+----------------------+----------------------+\n",
|
||||
" \n",
|
||||
"+---------------------------------------------------------------------------------------+\n",
|
||||
"| Processes: |\n",
|
||||
"| GPU GI CI PID Type Process name GPU Memory |\n",
|
||||
"| ID ID Usage |\n",
|
||||
"|=======================================================================================|\n",
|
||||
"+---------------------------------------------------------------------------------------+\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# 检查当前机器是可以使用 GPU,并且已经安装了正确的 CUDA 版本\n",
|
||||
"!nvidia-smi"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "92789975-f714-4258-815f-a3383ff1025e",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T07:39:27.551763Z",
|
||||
"iopub.status.busy": "2024-10-11T07:39:27.551350Z",
|
||||
"iopub.status.idle": "2024-10-11T07:39:27.564323Z",
|
||||
"shell.execute_reply": "2024-10-11T07:39:27.563116Z",
|
||||
"shell.execute_reply.started": "2024-10-11T07:39:27.551728Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
"\n",
|
||||
"## Qwen/Qwen2.5-0.5B-Instruct\n",
|
||||
"假定用户已经对机器学习(ML) 和深度学习(DL) 有一定的了解, 第一部就是加载一个模型进行推理预测。可以对模型和 tokenizer 进行分别加载."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "c75a18db",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"os.environ[\"HF_HOME\"] = \"/openbayes/home/huggingface\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "fd34a03a",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/openbayes/home/huggingface\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!echo $HF_HOME"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "502af603-cffa-4e19-b582-39de47038fbf",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T08:00:58.279143Z",
|
||||
"iopub.status.busy": "2024-10-11T08:00:58.278713Z",
|
||||
"iopub.status.idle": "2024-10-11T08:00:59.439221Z",
|
||||
"shell.execute_reply": "2024-10-11T08:00:59.438712Z",
|
||||
"shell.execute_reply.started": "2024-10-11T08:00:58.279109Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Qwen2ForCausalLM(\n",
|
||||
" (model): Qwen2Model(\n",
|
||||
" (embed_tokens): Embedding(151936, 896)\n",
|
||||
" (layers): ModuleList(\n",
|
||||
" (0-23): 24 x Qwen2DecoderLayer(\n",
|
||||
" (self_attn): Qwen2SdpaAttention(\n",
|
||||
" (q_proj): Linear(in_features=896, out_features=896, bias=True)\n",
|
||||
" (k_proj): Linear(in_features=896, out_features=128, bias=True)\n",
|
||||
" (v_proj): Linear(in_features=896, out_features=128, bias=True)\n",
|
||||
" (o_proj): Linear(in_features=896, out_features=896, bias=False)\n",
|
||||
" (rotary_emb): Qwen2RotaryEmbedding()\n",
|
||||
" )\n",
|
||||
" (mlp): Qwen2MLP(\n",
|
||||
" (gate_proj): Linear(in_features=896, out_features=4864, bias=False)\n",
|
||||
" (up_proj): Linear(in_features=896, out_features=4864, bias=False)\n",
|
||||
" (down_proj): Linear(in_features=4864, out_features=896, bias=False)\n",
|
||||
" (act_fn): SiLU()\n",
|
||||
" )\n",
|
||||
" (input_layernorm): Qwen2RMSNorm()\n",
|
||||
" (post_attention_layernorm): Qwen2RMSNorm()\n",
|
||||
" )\n",
|
||||
" )\n",
|
||||
" (norm): Qwen2RMSNorm()\n",
|
||||
" )\n",
|
||||
" (lm_head): Linear(in_features=896, out_features=151936, bias=False)\n",
|
||||
")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# 加载模型和 tokenizer (第一次加载的时候会进行下载)\n",
|
||||
"model = AutoModelForCausalLM.from_pretrained(\n",
|
||||
" \"Qwen/Qwen2.5-0.5B-Instruct\",\n",
|
||||
" device_map=\"cuda\",\n",
|
||||
" torch_dtype=\"auto\",\n",
|
||||
" trust_remote_code=True,\n",
|
||||
")\n",
|
||||
"# 查看 模型结构是什么?\n",
|
||||
"print(model)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"id": "ba34a386-1047-4a7a-adf3-554d53451717",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T07:54:03.311834Z",
|
||||
"iopub.status.busy": "2024-10-11T07:54:03.311382Z",
|
||||
"iopub.status.idle": "2024-10-11T07:54:03.782818Z",
|
||||
"shell.execute_reply": "2024-10-11T07:54:03.782328Z",
|
||||
"shell.execute_reply.started": "2024-10-11T07:54:03.311799Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'eos_token': '<|im_end|>',\n",
|
||||
" 'pad_token': '<|endoftext|>',\n",
|
||||
" 'additional_special_tokens': ['<|im_start|>',\n",
|
||||
" '<|im_end|>',\n",
|
||||
" '<|object_ref_start|>',\n",
|
||||
" '<|object_ref_end|>',\n",
|
||||
" '<|box_start|>',\n",
|
||||
" '<|box_end|>',\n",
|
||||
" '<|quad_start|>',\n",
|
||||
" '<|quad_end|>',\n",
|
||||
" '<|vision_start|>',\n",
|
||||
" '<|vision_end|>',\n",
|
||||
" '<|vision_pad|>',\n",
|
||||
" '<|image_pad|>',\n",
|
||||
" '<|video_pad|>']}"
|
||||
]
|
||||
},
|
||||
"execution_count": 20,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# 这里有一个 Special token, 打印看一下是什么token呢?\n",
|
||||
"tokenizer = AutoTokenizer.from_pretrained(\"Qwen/Qwen2.5-0.5B-Instruct\")\n",
|
||||
"# tokenizer.all_special_tokens\n",
|
||||
"tokenizer.special_tokens_map"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"id": "a815b098-0eb7-4959-b234-5f2de29baabd",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T07:54:59.563955Z",
|
||||
"iopub.status.busy": "2024-10-11T07:54:59.563516Z",
|
||||
"iopub.status.idle": "2024-10-11T07:54:59.568582Z",
|
||||
"shell.execute_reply": "2024-10-11T07:54:59.567943Z",
|
||||
"shell.execute_reply.started": "2024-10-11T07:54:59.563920Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# 每一个模型的 special token 都是不一样的(但是大同小异)\n",
|
||||
"# tokenizer = AutoTokenizer.from_pretrained(\"/openbayes/input/input0\")\n",
|
||||
"# tokenizer.special_tokens_map"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "7ac2ba87-c5c8-46bb-aa4b-c496f0d42acf",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T07:41:24.660416Z",
|
||||
"iopub.status.busy": "2024-10-11T07:41:24.660193Z",
|
||||
"iopub.status.idle": "2024-10-11T07:41:25.156935Z",
|
||||
"shell.execute_reply": "2024-10-11T07:41:25.155779Z",
|
||||
"shell.execute_reply.started": "2024-10-11T07:41:24.660400Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
"## 基础使用方式\n",
|
||||
"加载模型之后可以怎么使用呢?可以直接使用原始的 model 和 tokenizer 进行推理;\n",
|
||||
"\n",
|
||||
"- step1: 加载模型\n",
|
||||
"- step2: 构建 prompt 和 tokenizer\n",
|
||||
"- step3: 推理和解码\n",
|
||||
"\n",
|
||||
"刚刚已经加载过模型了,所以直接进行 step2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 38,
|
||||
"id": "d2650df5-3b05-4ba5-9f43-3bce0c31e9eb",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T08:00:36.492148Z",
|
||||
"iopub.status.busy": "2024-10-11T08:00:36.491852Z",
|
||||
"iopub.status.idle": "2024-10-11T08:00:36.499648Z",
|
||||
"shell.execute_reply": "2024-10-11T08:00:36.499240Z",
|
||||
"shell.execute_reply.started": "2024-10-11T08:00:36.492129Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"<|im_start|>system\n",
|
||||
"You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n",
|
||||
"<|im_start|>user\n",
|
||||
"讲一个猫有关的笑话?<|im_end|>\n",
|
||||
"<|im_start|>assistant\n",
|
||||
"\n",
|
||||
"========================================\n",
|
||||
"{'input_ids': tensor([[151644, 8948, 198, 2610, 525, 1207, 16948, 11, 3465,\n",
|
||||
" 553, 54364, 14817, 13, 1446, 525, 264, 10950, 17847,\n",
|
||||
" 13, 151645, 198, 151644, 872, 198, 99526, 46944, 100472,\n",
|
||||
" 101063, 9370, 109959, 11319, 151645, 198, 151644, 77091, 198]],\n",
|
||||
" device='cuda:0'), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
|
||||
" 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], device='cuda:0')}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"prompt = \"讲一个猫有关的笑话?\"\n",
|
||||
"messages = [\n",
|
||||
" {\"role\": \"system\", \"content\": \"You are Qwen, created by Alibaba Cloud. You are a helpful assistant.\"},\n",
|
||||
" {\"role\": \"user\", \"content\": prompt}\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# 想一下诗变成什么格式\n",
|
||||
"text = tokenizer.apply_chat_template(\n",
|
||||
" messages,\n",
|
||||
" tokenize=False,\n",
|
||||
" add_generation_prompt=True\n",
|
||||
")\n",
|
||||
"model_inputs = tokenizer([text], return_tensors=\"pt\").to(model.device)\n",
|
||||
"\n",
|
||||
"print(text)\n",
|
||||
"print(\"====\" * 10)\n",
|
||||
"print(model_inputs)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 41,
|
||||
"id": "304265f3-16c7-4b76-89d1-991bd5628022",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T08:02:02.184269Z",
|
||||
"iopub.status.busy": "2024-10-11T08:02:02.183829Z",
|
||||
"iopub.status.idle": "2024-10-11T08:02:03.095914Z",
|
||||
"shell.execute_reply": "2024-10-11T08:02:03.095439Z",
|
||||
"shell.execute_reply.started": "2024-10-11T08:02:02.184233Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"有一只猫对一只小老鼠说:“你真聪明,能帮我找到妈妈!” 小老鼠想了想,回答道:“是啊,我叫‘小红帽’。” 这只猫听了哈哈大笑起来。\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# step3: 推理和解码\n",
|
||||
"generated_ids = model.generate(\n",
|
||||
" **model_inputs,\n",
|
||||
" max_new_tokens=512\n",
|
||||
")\n",
|
||||
"generated_ids = [\n",
|
||||
" output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]\n",
|
||||
"print(response)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "35e6c259-989a-4b1e-8f2f-b3d420af24dd",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 使用 transformers 的 pipeline 简化流程"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 44,
|
||||
"id": "cac58a8f-09e3-43df-9650-52956254c420",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T08:04:15.400688Z",
|
||||
"iopub.status.busy": "2024-10-11T08:04:15.400052Z",
|
||||
"iopub.status.idle": "2024-10-11T08:04:19.558456Z",
|
||||
"shell.execute_reply": "2024-10-11T08:04:19.557925Z",
|
||||
"shell.execute_reply.started": "2024-10-11T08:04:15.400651Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/output/envs/hands-on-llm/lib/python3.10/site-packages/transformers/generation/configuration_utils.py:515: UserWarning: `do_sample` is set to `False`. However, `temperature` is set to `0.7` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `temperature`.\n",
|
||||
" warnings.warn(\n",
|
||||
"/output/envs/hands-on-llm/lib/python3.10/site-packages/transformers/generation/configuration_utils.py:520: UserWarning: `do_sample` is set to `False`. However, `top_p` is set to `0.8` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `top_p`.\n",
|
||||
" warnings.warn(\n",
|
||||
"/output/envs/hands-on-llm/lib/python3.10/site-packages/transformers/generation/configuration_utils.py:537: UserWarning: `do_sample` is set to `False`. However, `top_k` is set to `20` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `top_k`.\n",
|
||||
" warnings.warn(\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"好的,以下是一个关于猫的笑话:\n",
|
||||
"\n",
|
||||
"有一天,一只猫在森林里迷路了。它四处张望,但什么也看不见。突然,它看到了一棵树上挂着一个牌子,上面写着“欢迎光临”。猫好奇地走过去,发现牌子后面有一个小洞。\n",
|
||||
"\n",
|
||||
"猫小心翼翼地走进洞穴,里面有一只小老鼠正在吃着食物。猫对老鼠说:“你好,我是来自森林的小动物。”老鼠回答道:“我叫米奇,很高兴见到你。”\n",
|
||||
"\n",
|
||||
"猫对米奇说:“我也很高兴遇见你,但我需要一些食物来养活自己。”米奇笑了笑,说:“那我就给你煮个饭吧,你尝尝看。”\n",
|
||||
"\n",
|
||||
"于是,猫和米奇一起开始烹饪食物。猫用它的爪子扒开泥土,米奇则用他的牙齿咬碎坚果。他们一边吃一边聊,很快就度过了一个愉快的夜晚。\n",
|
||||
"\n",
|
||||
"这个故事告诉我们,有时候,我们可能会遇到各种各样的人或事,但只要我们保持耐心、友好,并且乐于分享我们的经历,就有可能结识到新朋友。\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from transformers import pipeline\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# step1: 生成 pipeline\n",
|
||||
"generator = pipeline(\n",
|
||||
" \"text-generation\",\n",
|
||||
" model=model,\n",
|
||||
" tokenizer=tokenizer,\n",
|
||||
" return_full_text=False,\n",
|
||||
" max_new_tokens=500,\n",
|
||||
" do_sample=False\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# step2: 构建 prompt\n",
|
||||
"messages = [\n",
|
||||
" {\"role\": \"user\", \"content\": \"写一个和猫有关的笑话.\"}\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# step3,输出并解码\n",
|
||||
"output = generator(messages)\n",
|
||||
"print(output[0][\"generated_text\"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 49,
|
||||
"id": "586b6f58-8623-431e-ad76-afa8de650064",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T08:04:49.207035Z",
|
||||
"iopub.status.busy": "2024-10-11T08:04:49.206594Z",
|
||||
"iopub.status.idle": "2024-10-11T08:04:49.213341Z",
|
||||
"shell.execute_reply": "2024-10-11T08:04:49.212867Z",
|
||||
"shell.execute_reply.started": "2024-10-11T08:04:49.207001Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[{'generated_text': '好的,以下是一个关于猫的笑话:\\n\\n有一天,一只猫在森林里迷路了。它四处张望,但什么也看不见。突然,它看到了一棵树上挂着一个牌子,上面写着“欢迎光临”。猫好奇地走过去,发现牌子后面有一个小洞。\\n\\n猫小心翼翼地走进洞穴,里面有一只小老鼠正在吃着食物。猫对老鼠说:“你好,我是来自森林的小动物。”老鼠回答道:“我叫米奇,很高兴见到你。”\\n\\n猫对米奇说:“我也很高兴遇见你,但我需要一些食物来养活自己。”米奇笑了笑,说:“那我就给你煮个饭吧,你尝尝看。”\\n\\n于是,猫和米奇一起开始烹饪食物。猫用它的爪子扒开泥土,米奇则用他的牙齿咬碎坚果。他们一边吃一边聊,很快就度过了一个愉快的夜晚。\\n\\n这个故事告诉我们,有时候,我们可能会遇到各种各样的人或事,但只要我们保持耐心、友好,并且乐于分享我们的经历,就有可能结识到新朋友。'}]"
|
||||
]
|
||||
},
|
||||
"execution_count": 49,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"output"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "hands-on-llm",
|
||||
"language": "python",
|
||||
"name": "hands-on-llm"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.15"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
@@ -0,0 +1,479 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4bb87b4e-7866-46e6-8214-7c9928a792a3",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Chapter 3 - Looking Inside Transformer LLMs\n",
|
||||
"\n",
|
||||
"## 加载 model 和 tokenizer"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "9f316e52-aebd-4165-8a4b-fd9d88e82dea",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T08:53:04.810236Z",
|
||||
"iopub.status.busy": "2024-10-11T08:53:04.809781Z",
|
||||
"iopub.status.idle": "2024-10-11T08:53:09.995918Z",
|
||||
"shell.execute_reply": "2024-10-11T08:53:09.995301Z",
|
||||
"shell.execute_reply.started": "2024-10-11T08:53:04.810211Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"model_name = \"Qwen/Qwen2.5-0.5B-Instruct\"\n",
|
||||
"# Load model and tokenizer\n",
|
||||
"tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
|
||||
"\n",
|
||||
"model = AutoModelForCausalLM.from_pretrained(\n",
|
||||
" model_name,\n",
|
||||
" device_map=\"cuda\",\n",
|
||||
" torch_dtype=\"auto\",\n",
|
||||
" trust_remote_code=True,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Create a pipeline\n",
|
||||
"generator = pipeline(\n",
|
||||
" \"text-generation\",\n",
|
||||
" model=model,\n",
|
||||
" tokenizer=tokenizer,\n",
|
||||
" return_full_text=False,\n",
|
||||
" max_new_tokens=50,\n",
|
||||
" do_sample=False,\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "026ca9c0-9aaf-475b-8111-f5132c1c752b",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T08:56:12.403160Z",
|
||||
"iopub.status.busy": "2024-10-11T08:56:12.402695Z",
|
||||
"iopub.status.idle": "2024-10-11T08:56:13.404874Z",
|
||||
"shell.execute_reply": "2024-10-11T08:56:13.404335Z",
|
||||
"shell.execute_reply.started": "2024-10-11T08:56:12.403124Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"( ) A. 李白 B. 白居易 C. 苏轼 D. 王安石\n",
|
||||
"李白\n",
|
||||
"\n",
|
||||
"“春眠不觉晓,处处闻啼鸟。夜来风雨声,花落知多少\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"prompt = \"春风又绿江南岸 是谁写的?\"\n",
|
||||
"output = generator(prompt)\n",
|
||||
"\n",
|
||||
"print(output[0]['generated_text'])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f119cf6d-7e32-4387-9036-fda91d428df0",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T08:58:44.961035Z",
|
||||
"iopub.status.busy": "2024-10-11T08:58:44.960572Z",
|
||||
"iopub.status.idle": "2024-10-11T08:58:44.964356Z",
|
||||
"shell.execute_reply": "2024-10-11T08:58:44.963816Z",
|
||||
"shell.execute_reply.started": "2024-10-11T08:58:44.960998Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
"### 备注 \n",
|
||||
"text-generation 仅仅是预测下一个token,所以相对于 如果没有构造成 [chat] 类的格式,效果会更差一些"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"id": "ec9ee6b5-6f28-4b89-be78-a461360e839b",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T08:59:04.296905Z",
|
||||
"iopub.status.busy": "2024-10-11T08:59:04.296413Z",
|
||||
"iopub.status.idle": "2024-10-11T08:59:04.303834Z",
|
||||
"shell.execute_reply": "2024-10-11T08:59:04.303185Z",
|
||||
"shell.execute_reply.started": "2024-10-11T08:59:04.296867Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Qwen2ForCausalLM(\n",
|
||||
" (model): Qwen2Model(\n",
|
||||
" (embed_tokens): Embedding(151936, 896)\n",
|
||||
" (layers): ModuleList(\n",
|
||||
" (0-23): 24 x Qwen2DecoderLayer(\n",
|
||||
" (self_attn): Qwen2SdpaAttention(\n",
|
||||
" (q_proj): Linear(in_features=896, out_features=896, bias=True)\n",
|
||||
" (k_proj): Linear(in_features=896, out_features=128, bias=True)\n",
|
||||
" (v_proj): Linear(in_features=896, out_features=128, bias=True)\n",
|
||||
" (o_proj): Linear(in_features=896, out_features=896, bias=False)\n",
|
||||
" (rotary_emb): Qwen2RotaryEmbedding()\n",
|
||||
" )\n",
|
||||
" (mlp): Qwen2MLP(\n",
|
||||
" (gate_proj): Linear(in_features=896, out_features=4864, bias=False)\n",
|
||||
" (up_proj): Linear(in_features=896, out_features=4864, bias=False)\n",
|
||||
" (down_proj): Linear(in_features=4864, out_features=896, bias=False)\n",
|
||||
" (act_fn): SiLU()\n",
|
||||
" )\n",
|
||||
" (input_layernorm): Qwen2RMSNorm()\n",
|
||||
" (post_attention_layernorm): Qwen2RMSNorm()\n",
|
||||
" )\n",
|
||||
" )\n",
|
||||
" (norm): Qwen2RMSNorm()\n",
|
||||
" )\n",
|
||||
" (lm_head): Linear(in_features=896, out_features=151936, bias=False)\n",
|
||||
")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print(model)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8a1d4e00-0c27-4841-8157-59bf403bf2f3",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T09:01:20.989997Z",
|
||||
"iopub.status.busy": "2024-10-11T09:01:20.989510Z",
|
||||
"iopub.status.idle": "2024-10-11T09:01:20.996292Z",
|
||||
"shell.execute_reply": "2024-10-11T09:01:20.995326Z",
|
||||
"shell.execute_reply.started": "2024-10-11T09:01:20.989961Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
"## 面试要点?\n",
|
||||
"- RMSNorm 和 layernorm 的区别?\n",
|
||||
"> RMSNorm 可学习参数少于 layernorm,计算量更小。\n",
|
||||
"> RMSNorm 只有缩放操作,没有 recenter 的操作。"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "718f3535-6a5d-4e08-8937-b71d6476e33b",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 查看一个 token 的概率分布(采样和解码)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"id": "1aacff57-4c66-42a4-a88b-3320e5f647ba",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T09:03:31.183503Z",
|
||||
"iopub.status.busy": "2024-10-11T09:03:31.183038Z",
|
||||
"iopub.status.idle": "2024-10-11T09:03:31.238394Z",
|
||||
"shell.execute_reply": "2024-10-11T09:03:31.237886Z",
|
||||
"shell.execute_reply.started": "2024-10-11T09:03:31.183467Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"prompt = \"The capital of France is\"\n",
|
||||
"\n",
|
||||
"input_ids = tokenizer(prompt, return_tensors=\"pt\").input_ids\n",
|
||||
"\n",
|
||||
"input_ids = input_ids.to(\"cuda\")\n",
|
||||
"\n",
|
||||
"# Get the output of the model before the lm_head\n",
|
||||
"model_output = model.model(input_ids)\n",
|
||||
"\n",
|
||||
"# Get the output of the lm_head\n",
|
||||
"lm_head_output = model.lm_head(model_output[0])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"id": "b3740b3a-30c4-4771-9869-dad58082396a",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T09:03:32.599936Z",
|
||||
"iopub.status.busy": "2024-10-11T09:03:32.599582Z",
|
||||
"iopub.status.idle": "2024-10-11T09:03:32.603959Z",
|
||||
"shell.execute_reply": "2024-10-11T09:03:32.603211Z",
|
||||
"shell.execute_reply.started": "2024-10-11T09:03:32.599917Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"' Paris'"
|
||||
]
|
||||
},
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"token_id = lm_head_output[0, -1].argmax(-1)\n",
|
||||
"tokenizer.decode(token_id)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"id": "d3730ac6-ba60-43b5-bbf0-b51cb15eb5d0",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T09:09:10.593567Z",
|
||||
"iopub.status.busy": "2024-10-11T09:09:10.593014Z",
|
||||
"iopub.status.idle": "2024-10-11T09:09:10.599657Z",
|
||||
"shell.execute_reply": "2024-10-11T09:09:10.599152Z",
|
||||
"shell.execute_reply.started": "2024-10-11T09:09:10.593514Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"tensor([[ 785, 6722, 315, 9625, 374]], device='cuda:0')"
|
||||
]
|
||||
},
|
||||
"execution_count": 24,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"input_ids"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 22,
|
||||
"id": "27ad6b6a-3c4f-4210-bf05-973deb1dfb75",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T09:08:38.621677Z",
|
||||
"iopub.status.busy": "2024-10-11T09:08:38.621192Z",
|
||||
"iopub.status.idle": "2024-10-11T09:08:38.628371Z",
|
||||
"shell.execute_reply": "2024-10-11T09:08:38.627777Z",
|
||||
"shell.execute_reply.started": "2024-10-11T09:08:38.621639Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(torch.Size([1, 5, 896]), torch.Size([1, 5, 151936]))"
|
||||
]
|
||||
},
|
||||
"execution_count": 22,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# 896 是模型的 config.hidden_state\n",
|
||||
"model_output[0].shape, lm_head_output.shape"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "99f7d4b6-dce4-40fb-b141-a63885f5a9e9",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "eb27cf0d-7c1e-4784-8c66-a6446f888cf3",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T09:09:52.210657Z",
|
||||
"iopub.status.busy": "2024-10-11T09:09:52.210124Z",
|
||||
"iopub.status.idle": "2024-10-11T09:09:52.215901Z",
|
||||
"shell.execute_reply": "2024-10-11T09:09:52.214703Z",
|
||||
"shell.execute_reply.started": "2024-10-11T09:09:52.210635Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
"### 备注 \n",
|
||||
"这里有两个 API, model.model() 和 model.lm_head()\n",
|
||||
"> model.model 是获取每一个 token hidden state, lm_head 是做 softmax 判断每一词是什么? "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "9ecf33e6-3e13-4e5d-b506-225d8189b263",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T09:11:31.201890Z",
|
||||
"iopub.status.busy": "2024-10-11T09:11:31.201440Z",
|
||||
"iopub.status.idle": "2024-10-11T09:11:31.206333Z",
|
||||
"shell.execute_reply": "2024-10-11T09:11:31.205251Z",
|
||||
"shell.execute_reply.started": "2024-10-11T09:11:31.201853Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
"## 使用 KV cache 加速"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 27,
|
||||
"id": "1e716c33-0d88-4ffb-a94b-da122ff99edb",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T09:12:00.719194Z",
|
||||
"iopub.status.busy": "2024-10-11T09:12:00.718878Z",
|
||||
"iopub.status.idle": "2024-10-11T09:12:00.731282Z",
|
||||
"shell.execute_reply": "2024-10-11T09:12:00.730535Z",
|
||||
"shell.execute_reply.started": "2024-10-11T09:12:00.719177Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"prompt = \"Write a very long email apologizing to Sarah for the tragic gardening mishap. Explain how it happened.\"\n",
|
||||
"\n",
|
||||
"# Tokenize the input prompt\n",
|
||||
"input_ids = tokenizer(prompt, return_tensors=\"pt\").input_ids\n",
|
||||
"input_ids = input_ids.to(\"cuda\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 30,
|
||||
"id": "265e32f0-e272-4e62-aaa4-4be8a790b14e",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T09:13:57.178245Z",
|
||||
"iopub.status.busy": "2024-10-11T09:13:57.177337Z",
|
||||
"iopub.status.idle": "2024-10-11T09:15:40.755634Z",
|
||||
"shell.execute_reply": "2024-10-11T09:15:40.754837Z",
|
||||
"shell.execute_reply.started": "2024-10-11T09:13:57.178227Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"14.8 s ± 4.58 s per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%%timeit -n 1\n",
|
||||
"# Generate the text\n",
|
||||
"generation_output = model.generate(\n",
|
||||
" input_ids=input_ids,\n",
|
||||
" max_new_tokens=1000,\n",
|
||||
" use_cache=True\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"id": "315e0313-1964-48f2-981a-a84d1da35f34",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-10-11T09:15:40.757424Z",
|
||||
"iopub.status.busy": "2024-10-11T09:15:40.757106Z",
|
||||
"iopub.status.idle": "2024-10-11T09:17:37.545535Z",
|
||||
"shell.execute_reply": "2024-10-11T09:17:37.544849Z",
|
||||
"shell.execute_reply.started": "2024-10-11T09:15:40.757395Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"16.7 s ± 5.17 s per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%%timeit -n 1\n",
|
||||
"# Generate the text\n",
|
||||
"generation_output = model.generate(\n",
|
||||
" input_ids=input_ids,\n",
|
||||
" max_new_tokens=1000,\n",
|
||||
" use_cache=False\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f6d4f3f7-3544-46c9-aed7-ea91f9a07ed0",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "hands-on-llm",
|
||||
"language": "python",
|
||||
"name": "hands-on-llm"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.15"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
|
After Width: | Height: | Size: 252 KiB |
|
After Width: | Height: | Size: 292 KiB |
|
After Width: | Height: | Size: 356 KiB |
@@ -0,0 +1,248 @@
|
||||
name: thellmbook
|
||||
channels:
|
||||
- conda-forge
|
||||
- defaults
|
||||
dependencies:
|
||||
- bzip2=1.0.8
|
||||
- ca-certificates=2024.8.30
|
||||
- libffi=3.4.2
|
||||
- libsqlite=3.46.1
|
||||
- libzlib=1.3.1
|
||||
- openssl=3.3.2
|
||||
- pip=24.2
|
||||
- python=3.10.14
|
||||
- setuptools=73.0.1
|
||||
- tk=8.6.13
|
||||
- ucrt=10.0.22621.0
|
||||
- vc=14.3
|
||||
- vc14_runtime=14.40.33810
|
||||
- vs2015_runtime=14.40.33810
|
||||
- wheel=0.44.0
|
||||
- xz=5.2.6
|
||||
- pip:
|
||||
- accelerate==0.31.0
|
||||
- aiohappyeyeballs==2.4.0
|
||||
- aiohttp==3.10.5
|
||||
- aiosignal==1.3.1
|
||||
- annotated-types==0.7.0
|
||||
- annoy==1.17.3
|
||||
- anyio==4.4.0
|
||||
- argon2-cffi==23.1.0
|
||||
- argon2-cffi-bindings==21.2.0
|
||||
- arrow==1.3.0
|
||||
- asttokens==2.4.1
|
||||
- async-lru==2.0.4
|
||||
- async-timeout==4.0.3
|
||||
- attrs==24.2.0
|
||||
- babel==2.16.0
|
||||
- beautifulsoup4==4.12.3
|
||||
- bertopic==0.16.3
|
||||
- bitsandbytes==0.43.1
|
||||
- bleach==6.1.0
|
||||
- boto3==1.35.15
|
||||
- botocore==1.35.15
|
||||
- certifi==2024.8.30
|
||||
- cffi==1.17.1
|
||||
- charset-normalizer==3.3.2
|
||||
- click==8.1.7
|
||||
- cloudpickle==3.0.0
|
||||
- cohere==5.5.8
|
||||
- colorama==0.4.6
|
||||
- colorcet==3.1.0
|
||||
- colorspacious==1.1.2
|
||||
- comm==0.2.2
|
||||
- contourpy==1.3.0
|
||||
- cycler==0.12.1
|
||||
- dask==2024.8.2
|
||||
- dataclasses-json==0.6.7
|
||||
- datamapplot==0.3.0
|
||||
- datasets==2.20.0
|
||||
- datashader==0.16.3
|
||||
- debugpy==1.8.5
|
||||
- decorator==5.1.1
|
||||
- defusedxml==0.7.1
|
||||
- dill==0.3.8
|
||||
- diskcache==5.6.3
|
||||
- distro==1.9.0
|
||||
- docstring-parser==0.16
|
||||
- duckduckgo-search==6.1.6
|
||||
- eval-type-backport==0.2.0
|
||||
- evaluate==0.4.2
|
||||
- exceptiongroup==1.2.2
|
||||
- executing==2.1.0
|
||||
- fastavro==1.9.7
|
||||
- fastjsonschema==2.20.0
|
||||
- filelock==3.16.0
|
||||
- fonttools==4.53.1
|
||||
- fqdn==1.5.1
|
||||
- frozenlist==1.4.1
|
||||
- fsspec==2024.5.0
|
||||
- gensim==4.3.2
|
||||
- greenlet==3.0.3
|
||||
- h11==0.14.0
|
||||
- hdbscan==0.8.38.post1
|
||||
- httpcore==1.0.5
|
||||
- httpx==0.27.2
|
||||
- httpx-sse==0.4.0
|
||||
- huggingface-hub==0.24.6
|
||||
- idna==3.8
|
||||
- imageio==2.35.1
|
||||
- importlib-metadata==8.4.0
|
||||
- intel-openmp==2021.4.0
|
||||
- ipykernel==6.29.5
|
||||
- ipython==8.27.0
|
||||
- ipywidgets==8.1.3
|
||||
- isoduration==20.11.0
|
||||
- jedi==0.19.1
|
||||
- jinja2==3.1.4
|
||||
- jmespath==1.0.1
|
||||
- joblib==1.4.2
|
||||
- json5==0.9.25
|
||||
- jsonpatch==1.33
|
||||
- jsonpointer==3.0.0
|
||||
- jsonschema==4.23.0
|
||||
- jsonschema-specifications==2023.12.1
|
||||
- jupyter-client==8.6.2
|
||||
- jupyter-core==5.7.2
|
||||
- jupyter-events==0.10.0
|
||||
- jupyter-lsp==2.2.5
|
||||
- jupyter-server==2.14.2
|
||||
- jupyter-server-terminals==0.5.3
|
||||
- jupyterlab==4.2.2
|
||||
- jupyterlab-pygments==0.3.0
|
||||
- jupyterlab-server==2.27.3
|
||||
- jupyterlab-widgets==3.0.13
|
||||
- kiwisolver==1.4.7
|
||||
- langchain==0.2.5
|
||||
- langchain-community==0.2.5
|
||||
- langchain-core==0.2.38
|
||||
- langchain-openai==0.1.8
|
||||
- langchain-text-splitters==0.2.4
|
||||
- langsmith==0.1.117
|
||||
- lazy-loader==0.4
|
||||
- llama-cpp-python==0.2.78
|
||||
- llvmlite==0.43.0
|
||||
- locket==1.0.0
|
||||
- markdown-it-py==3.0.0
|
||||
- markupsafe==2.1.5
|
||||
- marshmallow==3.22.0
|
||||
- matplotlib==3.9.0
|
||||
- matplotlib-inline==0.1.7
|
||||
- mdurl==0.1.2
|
||||
- mistune==3.0.2
|
||||
- mkl==2021.4.0
|
||||
- mpmath==1.3.0
|
||||
- mteb==1.12.39
|
||||
- multidict==6.1.0
|
||||
- multipledispatch==1.0.0
|
||||
- multiprocess==0.70.16
|
||||
- mypy-extensions==1.0.0
|
||||
- nbclient==0.10.0
|
||||
- nbconvert==7.16.4
|
||||
- nbformat==5.10.4
|
||||
- nest-asyncio==1.6.0
|
||||
- networkx==3.3
|
||||
- nltk==3.8.1
|
||||
- notebook-shim==0.2.4
|
||||
- numba==0.60.0
|
||||
- numexpr==2.10.0
|
||||
- numpy==1.26.4
|
||||
- openai==1.34.0
|
||||
- orjson==3.10.7
|
||||
- overrides==7.7.0
|
||||
- packaging==24.1
|
||||
- pandas==2.2.2
|
||||
- pandocfilters==1.5.1
|
||||
- param==2.1.1
|
||||
- parameterized==0.9.0
|
||||
- parso==0.8.4
|
||||
- partd==1.4.2
|
||||
- peft==0.11.1
|
||||
- pillow==10.4.0
|
||||
- platformdirs==4.3.2
|
||||
- plotly==5.24.0
|
||||
- polars==1.6.0
|
||||
- prometheus-client==0.20.0
|
||||
- prompt-toolkit==3.0.47
|
||||
- psutil==6.0.0
|
||||
- pure-eval==0.2.3
|
||||
- pyarrow==17.0.0
|
||||
- pyarrow-hotfix==0.6
|
||||
- pycparser==2.22
|
||||
- pyct==0.5.0
|
||||
- pydantic==2.9.1
|
||||
- pydantic-core==2.23.3
|
||||
- pygments==2.18.0
|
||||
- pylabeladjust==0.1.13
|
||||
- pynndescent==0.5.13
|
||||
- pyparsing==3.1.4
|
||||
- pyqtree==1.0.0
|
||||
- pyreqwest-impersonate==0.5.3
|
||||
- python-dateutil==2.9.0.post0
|
||||
- python-json-logger==2.0.7
|
||||
- pytrec-eval-terrier==0.5.6
|
||||
- pytz==2024.1
|
||||
- pywin32==306
|
||||
- pywinpty==2.0.13
|
||||
- pyyaml==6.0.2
|
||||
- pyzmq==26.2.0
|
||||
- referencing==0.35.1
|
||||
- regex==2024.7.24
|
||||
- requests==2.32.3
|
||||
- rfc3339-validator==0.1.4
|
||||
- rfc3986-validator==0.1.1
|
||||
- rich==13.8.1
|
||||
- rpds-py==0.20.0
|
||||
- s3transfer==0.10.2
|
||||
- safetensors==0.4.5
|
||||
- scikit-image==0.24.0
|
||||
- scikit-learn==1.5.0
|
||||
- send2trash==1.8.3
|
||||
- sentence-transformers==3.0.1
|
||||
- sentencepiece==0.2.0
|
||||
- seqeval==1.2.2
|
||||
- setfit==1.0.3
|
||||
- shtab==1.7.1
|
||||
- six==1.16.0
|
||||
- smart-open==7.0.4
|
||||
- sniffio==1.3.1
|
||||
- soupsieve==2.6
|
||||
- sqlalchemy==2.0.34
|
||||
- stack-data==0.6.3
|
||||
- sympy==1.13.2
|
||||
- tbb==2021.13.1
|
||||
- tenacity==8.5.0
|
||||
- terminado==0.18.1
|
||||
- threadpoolctl==3.5.0
|
||||
- tifffile==2024.8.30
|
||||
- tiktoken==0.7.0
|
||||
- tinycss2==1.3.0
|
||||
- tokenizers==0.19.1
|
||||
- tomli==2.0.1
|
||||
- toolz==0.12.1
|
||||
- torch==2.3.1
|
||||
- tornado==6.4.1
|
||||
- tqdm==4.66.5
|
||||
- traitlets==5.14.3
|
||||
- transformers==4.41.2
|
||||
- trl==0.9.4
|
||||
- types-python-dateutil==2.9.0.20240906
|
||||
- types-requests==2.32.0.20240907
|
||||
- typing-extensions==4.12.2
|
||||
- typing-inspect==0.9.0
|
||||
- tyro==0.8.10
|
||||
- tzdata==2024.1
|
||||
- umap-learn==0.5.6
|
||||
- uri-template==1.3.0
|
||||
- urllib3==2.2.2
|
||||
- wcwidth==0.2.13
|
||||
- webcolors==24.8.0
|
||||
- webencodings==0.5.1
|
||||
- websocket-client==1.8.0
|
||||
- widgetsnbextension==4.0.13
|
||||
- wrapt==1.16.0
|
||||
- xarray==2024.7.0
|
||||
- xxhash==3.5.0
|
||||
- yarl==1.11.1
|
||||
- zipp==3.20.1
|
||||
prefix: C:\ProgramData\miniconda3\envs\thellmbook
|
||||
|
After Width: | Height: | Size: 257 KiB |
|
After Width: | Height: | Size: 182 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 106 KiB |
@@ -0,0 +1,43 @@
|
||||
# Data handling
|
||||
numpy == 1.26.4
|
||||
pandas == 2.2.2
|
||||
datasets == 2.20.0
|
||||
|
||||
# Environment
|
||||
jupyterlab == 4.2.2
|
||||
ipywidgets == 8.1.3
|
||||
|
||||
# Hard dependencies throughout the entire book
|
||||
torch == 2.3.1
|
||||
transformers == 4.41.2
|
||||
sentence-transformers == 3.0.1
|
||||
matplotlib == 3.9.0
|
||||
scikit-learn == 1.5.0
|
||||
sentencepiece == 0.2.0
|
||||
nltk == 3.8.1
|
||||
evaluate == 0.4.2
|
||||
scipy == 1.12.0 # TEMPORARY DEP BECAUSE OF https://github.com/piskvorky/gensim/issues/3525
|
||||
|
||||
# Cloud providers
|
||||
openai == 1.34.0
|
||||
cohere == 5.5.8
|
||||
|
||||
# Chapter-specific dependencies
|
||||
datamapplot == 0.3.0
|
||||
faiss-cpu==1.8.0
|
||||
bertopic == 0.16.3
|
||||
annoy == 1.17.3
|
||||
llama_cpp_python == 0.2.78 -C cmake.args="-DLLAMA_BLAS=ON"
|
||||
numexpr == 2.10.0
|
||||
langchain == 0.2.5
|
||||
langchain-community == 0.2.5
|
||||
langchain-openai==0.1.8
|
||||
duckduckgo-search == 6.1.6
|
||||
gensim == 4.3.2
|
||||
setfit == 1.0.3
|
||||
seqeval == 1.2.2
|
||||
trl == 0.9.4
|
||||
peft == 0.11.1
|
||||
accelerate == 0.31.0
|
||||
bitsandbytes == 0.43.1
|
||||
mteb == 1.12.39
|
||||
@@ -0,0 +1,43 @@
|
||||
# Data handling
|
||||
numpy >= 1.26.4
|
||||
pandas >= 2.2.2
|
||||
datasets >= 2.20.0
|
||||
|
||||
# Environment
|
||||
jupyterlab >= 4.2.2
|
||||
ipywidgets >= 8.1.3
|
||||
|
||||
# Hard dependencies throughout the entire book
|
||||
torch >= 2.3.1
|
||||
transformers >= 4.41.2
|
||||
sentence-transformers >= 3.0.1
|
||||
matplotlib >= 3.9.0
|
||||
scikit-learn >= 1.5.0
|
||||
sentencepiece >= 0.2.0
|
||||
nltk >= 3.8.1
|
||||
evaluate >= 0.4.2
|
||||
scipy == 1.12.0 # TEMPORARY DEP BECAUSE OF https://github.com/piskvorky/gensim/issues/3525
|
||||
|
||||
# Cloud providers
|
||||
openai >= 1.34.0
|
||||
cohere >= 5.5.8
|
||||
|
||||
# Chapter-specific dependencies
|
||||
datamapplot >= 0.3.0
|
||||
faiss-cpu >= 1.8.0
|
||||
bertopic >= 0.16.3
|
||||
annoy >= 1.17.3
|
||||
llama_cpp_python >= 0.2.78 -C cmake.args="-DLLAMA_BLAS=ON"
|
||||
numexpr >= 2.10.0
|
||||
langchain >= 0.2.5
|
||||
langchain-community >= 0.2.5
|
||||
langchain-openai >= 0.1.8
|
||||
duckduckgo-search >= 6.1.6
|
||||
gensim >= 4.3.2
|
||||
setfit >= 1.0.3
|
||||
seqeval >= 1.2.2
|
||||
trl >= 0.9.4
|
||||
peft >= 0.11.1
|
||||
accelerate >= 0.31.0
|
||||
bitsandbytes >= 0.43.1
|
||||
mteb >= 1.12.39
|
||||