{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, TextIteratorStreamer, BitsAndBytesConfig\n", "from threading import Thread\n", "import torch" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "model_path = \"/root/models/notebook\"" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "quantization_config = BitsAndBytesConfig(\n", " load_in_4bit=True,\n", " bnb_4bit_compute_dtype=torch.bfloat16,\n", " bnb_4bit_quant_type=\"nf4\",\n", " bnb_4bit_use_double_quant=True\n", ")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5f35aa01aafa4bc2beb19f437373945e", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Loading checkpoint shards: 0%| | 0/14 [00:00\n", "\n", "The word \"strawberry\" contains three 'r's. Here's the breakdown:\n", "\n", "1. **S** \n", "2. **T** \n", "3. **R** (first 'r') \n", "4. **A** \n", "5. **W** \n", "6. **B** \n", "7. **E** \n", "8. **R** (second 'r') \n", "9. **R** (third 'r') \n", "10. **Y** \n", "\n", "So, **there are 3 'r's in \"strawberry\"**.<|im_end|>" ] } ], "source": [ "for text in streamer:\n", " print(text, end='')" ] } ], "metadata": { "kernelspec": { "display_name": "train", "language": "python", "name": "python3" }, "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.12" } }, "nbformat": 4, "nbformat_minor": 2 }