{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import sys\n", "sys.path.append('../../../FinNLP/') # https://github.com/AI4Finance-Foundation/FinNLP" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[2023-08-04 17:08:33,847] [INFO] [real_accelerator.py:110:get_accelerator] Setting ds_accelerator to cuda (auto detect)\n" ] } ], "source": [ "from transformers import AutoModel, AutoTokenizer, AutoModelForCausalLM, LlamaForCausalLM, LlamaTokenizerFast # 4.30.2\n", "from peft import PeftModel # 0.4.0\n", "import torch\n", "\n", "from finnlp.benchmarks.fpb import test_fpb\n", "from finnlp.benchmarks.fiqa import test_fiqa , add_instructions\n", "from finnlp.benchmarks.tfns import test_tfns\n", "from finnlp.benchmarks.nwgi import test_nwgi" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load Model (Pick one according the model from the following blocks)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 1. **FInGPT v3.1** based on ChatGLM2, runable on 1 * RTX 3090" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# v3.1\n", "base_model = \"THUDM/chatglm2-6b\"\n", "peft_model = \"oliverwang15/FinGPT_v31_ChatGLM2_Sentiment_Instruction_LoRA_FT\"\n", "tokenizer = AutoTokenizer.from_pretrained(base_model, trust_remote_code=True)\n", "model = AutoModel.from_pretrained(base_model, trust_remote_code=True, load_in_8bit = True, device_map = \"auto\")\n", "model = PeftModel.from_pretrained(model, peft_model)\n", "model = model.eval()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 2. **FinGPT v3.2** based on Llama2, runable on 1 * A 100 and also runable on 1 * RTX 3090 as long as `load_in_8bit = True` is set in Line 8, but the speed is slower" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "The argument `trust_remote_code` is to be used with Auto classes. It has no effect here and is ignored.\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "21d8b449e1734815b004b8532621884a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Loading checkpoint shards: 0%| | 0/2 [00:00