File size: 2,778 Bytes
b72a02e
743cef1
 
 
4cfeb6c
743cef1
 
 
 
 
 
4cfeb6c
 
 
 
 
 
 
b72a02e
ab8a14a
 
 
743cef1
ab8a14a
743cef1
ab8a14a
e5531d4
f221b5a
743cef1
e5531d4
743cef1
e5531d4
743cef1
ab8a14a
 
 
743cef1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85331af
743cef1
85331af
743cef1
 
 
 
 
e5531d4
 
ab8a14a
e5531d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
---
language:
- en
license: llama2
library_name: peft
tags:
- facebook
- meta
- pytorch
- llama
- llama-2
base_model: DavidLanz/Llama2-tw-7B-v2.0.1-chat
model_name: Llama 2 7B Chat
inference: false
model_creator: Meta Llama 2
model_type: llama
pipeline_tag: text-generation
quantized_by: QLoRA
---

# Model Card for Model ID

This PEFT weight is for predicting BTC price.

Disclaimer: This model is for a time series problem on LLM performance, and it's not for investment advice; any prediction results are not a basis for investment reference.

## Model Details

Training data source: BTC/USD provided by [Binance](https://www.binance.com/).

### Model Description

This repo contains QLoRA format model files for [Meta's Llama 2 7B-chat](https://huggingface.co/DavidLanz/Llama2-tw-7B-v2.0.1-chat).

## Uses

```python
import torch
from peft import LoraConfig, PeftModel

from transformers import (
    AutoModelForCausalLM,
    AutoTokenizer,
    BitsAndBytesConfig,
    HfArgumentParser,
    TrainingArguments,
    TextStreamer,
    pipeline,
    logging,
)

device_map = {"": 0}
use_4bit = True
bnb_4bit_compute_dtype = "float16"
bnb_4bit_quant_type = "nf4"
use_nested_quant = False
compute_dtype = getattr(torch, bnb_4bit_compute_dtype)

bnb_config = BitsAndBytesConfig(
    load_in_4bit=use_4bit,
    bnb_4bit_quant_type=bnb_4bit_quant_type,
    bnb_4bit_compute_dtype=compute_dtype,
    bnb_4bit_use_double_quant=use_nested_quant,
)

based_model_path = "DavidLanz/Llama2-tw-7B-v2.0.1-chat"
adapter_path = "DavidLanz/llama2_7b_taiwan_btc_qlora"

base_model = AutoModelForCausalLM.from_pretrained(
    based_model_path,
    low_cpu_mem_usage=True,
    # load_in_4bit=True,
    return_dict=True,
    quantization_config=bnb_config,
    torch_dtype=torch.float16,
    device_map=device_map,
)
model = PeftModel.from_pretrained(base_model, adapter_path)

tokenizer = AutoTokenizer.from_pretrained(base_model_path, trust_remote_code=True)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = "right"

from transformers import pipeline

pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, torch_dtype=torch.bfloat16, device_map="auto")
messages = [
    {
        "role": "system",
        "content": "你是一位專業的BTC虛擬貨幣分析預測BTC的收盤價格。",
    },
    {"role": "user", "content": "昨日開盤價為64437.18,最高價為64960.37,最低價為62953.90,收盤價為64808.35,交易量為808273.27。請預測今日BTC的收盤價?"},
]
prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
print(outputs[0]["generated_text"])
```

### Framework versions

- PEFT 0.10.0