Safetensors
RAG hallucinations
Knowledge Conflict
wingchiuloong commited on
Commit
3c7b2ea
·
verified ·
1 Parent(s): 893c972

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +174 -202
README.md CHANGED
@@ -1,209 +1,181 @@
1
  ---
 
2
  base_model: meta-llama/Meta-Llama-3-8B-Instruct
3
- library_name: peft
4
- pipeline_tag: text-generation
5
  tags:
6
- - base_model:adapter:meta-llama/Meta-Llama-3-8B-Instruct
7
- - dpo
8
- - lora
9
- - transformers
10
- - trl
 
 
 
11
  ---
12
 
13
- # Model Card for Model ID
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- <!-- Provide a quick summary of what the model is/does. -->
16
-
17
-
18
-
19
- ## Model Details
20
-
21
- ### Model Description
22
-
23
- <!-- Provide a longer summary of what this model is. -->
24
-
25
-
26
-
27
- - **Developed by:** [More Information Needed]
28
- - **Funded by [optional]:** [More Information Needed]
29
- - **Shared by [optional]:** [More Information Needed]
30
- - **Model type:** [More Information Needed]
31
- - **Language(s) (NLP):** [More Information Needed]
32
- - **License:** [More Information Needed]
33
- - **Finetuned from model [optional]:** [More Information Needed]
34
-
35
- ### Model Sources [optional]
36
-
37
- <!-- Provide the basic links for the model. -->
38
-
39
- - **Repository:** [More Information Needed]
40
- - **Paper [optional]:** [More Information Needed]
41
- - **Demo [optional]:** [More Information Needed]
42
-
43
- ## Uses
44
-
45
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
46
-
47
- ### Direct Use
48
-
49
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
50
-
51
- [More Information Needed]
52
-
53
- ### Downstream Use [optional]
54
-
55
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
56
-
57
- [More Information Needed]
58
-
59
- ### Out-of-Scope Use
60
-
61
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
62
-
63
- [More Information Needed]
64
-
65
- ## Bias, Risks, and Limitations
66
-
67
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
68
-
69
- [More Information Needed]
70
-
71
- ### Recommendations
72
-
73
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
74
-
75
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
76
-
77
- ## How to Get Started with the Model
78
-
79
- Use the code below to get started with the model.
80
-
81
- [More Information Needed]
82
-
83
- ## Training Details
84
-
85
- ### Training Data
86
-
87
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
88
-
89
- [More Information Needed]
90
-
91
- ### Training Procedure
92
-
93
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
94
-
95
- #### Preprocessing [optional]
96
-
97
- [More Information Needed]
98
-
99
-
100
- #### Training Hyperparameters
101
-
102
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
103
-
104
- #### Speeds, Sizes, Times [optional]
105
-
106
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
107
-
108
- [More Information Needed]
109
-
110
- ## Evaluation
111
-
112
- <!-- This section describes the evaluation protocols and provides the results. -->
113
-
114
- ### Testing Data, Factors & Metrics
115
-
116
- #### Testing Data
117
-
118
- <!-- This should link to a Dataset Card if possible. -->
119
-
120
- [More Information Needed]
121
-
122
- #### Factors
123
-
124
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
125
-
126
- [More Information Needed]
127
-
128
- #### Metrics
129
-
130
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
131
-
132
- [More Information Needed]
133
-
134
- ### Results
135
-
136
- [More Information Needed]
137
-
138
- #### Summary
139
-
140
-
141
-
142
- ## Model Examination [optional]
143
-
144
- <!-- Relevant interpretability work for the model goes here -->
145
-
146
- [More Information Needed]
147
-
148
- ## Environmental Impact
149
-
150
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
151
-
152
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
153
-
154
- - **Hardware Type:** [More Information Needed]
155
- - **Hours used:** [More Information Needed]
156
- - **Cloud Provider:** [More Information Needed]
157
- - **Compute Region:** [More Information Needed]
158
- - **Carbon Emitted:** [More Information Needed]
159
-
160
- ## Technical Specifications [optional]
161
-
162
- ### Model Architecture and Objective
163
-
164
- [More Information Needed]
165
-
166
- ### Compute Infrastructure
167
-
168
- [More Information Needed]
169
-
170
- #### Hardware
171
-
172
- [More Information Needed]
173
-
174
- #### Software
175
-
176
- [More Information Needed]
177
-
178
- ## Citation [optional]
179
-
180
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
181
-
182
- **BibTeX:**
183
-
184
- [More Information Needed]
185
-
186
- **APA:**
187
-
188
- [More Information Needed]
189
-
190
- ## Glossary [optional]
191
-
192
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
193
-
194
- [More Information Needed]
195
-
196
- ## More Information [optional]
197
-
198
- [More Information Needed]
199
-
200
- ## Model Card Authors [optional]
201
-
202
- [More Information Needed]
203
-
204
- ## Model Card Contact
205
-
206
- [More Information Needed]
207
- ### Framework versions
208
 
209
- - PEFT 0.16.0
 
1
  ---
2
+ license: llama3
3
  base_model: meta-llama/Meta-Llama-3-8B-Instruct
 
 
4
  tags:
5
+ - RAG hallucinations
6
+ - Knowledge Conflict
7
+ datasets:
8
+ - qiaojin/PubMedQA
9
+ - Salesforce/FaithEval-counterfactual-v1.0
10
+ - wandb/RAGTruth-processed
11
+ metrics:
12
+ - accuracy
13
  ---
14
 
15
+ # CopyPasteLLM-L3-8B
16
+
17
+ ## Quick Start
18
+
19
+ ### Method 1: Using Transformers
20
+
21
+ ```python
22
+ #!/usr/bin/env python3
23
+ import torch
24
+ from transformers import (
25
+ AutoTokenizer,
26
+ AutoModelForCausalLM,
27
+ BitsAndBytesConfig,
28
+ pipeline
29
+ )
30
+ import warnings
31
+ warnings.filterwarnings("ignore")
32
+
33
+ def load_model_and_tokenizer():
34
+ """Load model and tokenizer"""
35
+ print("Loading model and tokenizer...")
36
+
37
+ # Base model configuration
38
+ base_model_name = "meta-llama/Meta-Llama-3-8B-Instruct"
39
+ lora_model_name = "wingchiuloong/CopyPasteLLM-L3-8B"
40
+
41
+ # Quantization configuration
42
+ quantization_config = BitsAndBytesConfig(
43
+ load_in_4bit=True,
44
+ bnb_4bit_compute_dtype=torch.float16,
45
+ bnb_4bit_use_double_quant=True,
46
+ bnb_4bit_quant_type="nf4"
47
+ )
48
+
49
+ # Load tokenizer
50
+ tokenizer = AutoTokenizer.from_pretrained(
51
+ base_model_name,
52
+ trust_remote_code=True
53
+ )
54
+
55
+ # Load base model
56
+ model = AutoModelForCausalLM.from_pretrained(
57
+ base_model_name,
58
+ quantization_config=quantization_config,
59
+ device_map="auto",
60
+ trust_remote_code=True,
61
+ torch_dtype=torch.float16
62
+ )
63
+
64
+ # Load LoRA weights
65
+ print("Loading LoRA weights...")
66
+ from peft import PeftModel
67
+ model = PeftModel.from_pretrained(model, lora_model_name)
68
+
69
+ return model, tokenizer
70
+
71
+ def create_pipeline(model, tokenizer):
72
+ """Create inference pipeline"""
73
+ return pipeline(
74
+ "text-generation",
75
+ model=model,
76
+ tokenizer=tokenizer,
77
+ torch_dtype=torch.float16,
78
+ device_map="auto"
79
+ )
80
+
81
+ def format_prompt(user_input):
82
+ """Format input to Llama-3 format"""
83
+ system_message = "You are a helpful AI assistant."
84
+
85
+ prompt = f"""<|begin_of_text|><|start_header_id|>system<|end_header_id|>
86
+
87
+ {system_message}<|eot_id|><|start_header_id|>user<|end_header_id|>
88
+
89
+ {user_input}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
90
+
91
+ """
92
+ return prompt
93
+
94
+ def main():
95
+ """Main function - One-time inference"""
96
+ print("CopyPasteLLM inference Demo")
97
+ print("=" * 50)
98
+
99
+ # Set test question
100
+ context = "Galileo Galilei, renowned as one of the most influential figures in the history of science, made numerous contributions that revolutionized our understanding of physics and astronomy. His meticulous work with telescopes led to groundbreaking discoveries about the moons of Jupiter and the phases of Venus. Beyond the realm of astronomy, his observations and experiments laid the foundation for classical mechanics. One of Galileo’s lesser-known achievements is his development of the Three Laws of Motion, which were critical in advancing the study of kinematics and dynamics. These laws articulate the principles of inertia, the relationship between force and motion, and the law of action and reaction, providing a comprehensive framework for understanding moving bodies. His work on pendulums also contributed substantially to timekeeping and horology, as he discovered that pendulums of different lengths oscillate at predictable periods, a principle still applied in modern clocks. Galileo’s interdisciplinary approach enabled him to synthesize knowledge from various fields, which allowed new theories to emerge, reshaping the scientific landscape of his time and beyond. Notably, his support of the heliocentric model of the solar system earned him both acclaim and censure, highlighting the tension between scientific inquiry and established doctrine. In contrast to Galen’s biological studies and Newton’s later contributions, Galileo’s articulation of the Three Laws of Motion was pivotal in the transition from Aristotelian physics to Newtonian mechanics. His contributions remain a testament to the interplay of observation, theory, and experimentation in scientific progress."
101
+ question = "Which law was Galileo Galilei responsible for describing?"
102
+ test_question = f"{context}\nQ: {question}\nA:"
103
+ print(f"{test_question}")
104
+ print("-" * 50)
105
+
106
+ try:
107
+ # Load model
108
+ model, tokenizer = load_model_and_tokenizer()
109
+
110
+ # Create pipeline
111
+ print("Creating inference pipeline...")
112
+ pipe = create_pipeline(model, tokenizer)
113
+
114
+ print("Model loaded! Starting inference...")
115
+
116
+ # Format input
117
+ prompt = format_prompt(test_question)
118
+
119
+ # Generate reply
120
+ print("Generating reply...")
121
+ outputs = pipe(
122
+ prompt,
123
+ max_new_tokens=512,
124
+ temperature=1.0,
125
+ top_p=0.95,
126
+ do_sample=True,
127
+ pad_token_id=tokenizer.eos_token_id,
128
+ eos_token_id=tokenizer.eos_token_id,
129
+ return_full_text=False
130
+ )
131
+
132
+ # Output result
133
+ response = outputs[0]['generated_text']
134
+ print(f"\nCopyPasteLLM:\n{response}") # According to the passage, Galileo Galilei was responsible for describing the Three Laws of Motion, which articulate the principles of inertia, the relationship between force and motion, and the law of action and reaction.
135
+
136
+ except Exception as e:
137
+ print(f"Inference failed: {e}")
138
+ print("Please ensure the necessary dependencies are installed: pip install transformers peft bitsandbytes accelerate")
139
+
140
+ if __name__ == "__main__":
141
+ main()
142
+ ```
143
+
144
+ ### Method 2: Using vLLM
145
+
146
+ ```bash
147
+ base_model="meta-llama/Meta-Llama-3-8B-Instruct"
148
+ lora_modules_path="<model_at_your_huggingface_cache>" # like "~/.huggingface/hub/models--wingchiuloong--CopyPasteLLM-L3-8B/snapshots/<uuid>"
149
+
150
+ python -m vllm.entrypoints.openai.api_server \
151
+ --model $base_model \
152
+ --enable-lora \
153
+ --max-lora-rank 64 \
154
+ --lora-modules CopyPasteLLM-8b=$lora_modules_path \
155
+ --host 0.0.0.0 \
156
+ --port 8888 \
157
+ --gpu-memory-utilization 0.8 \
158
+ --max-model-len 1024 \
159
+ --max-num-seqs 32 \
160
+ --tensor-parallel-size 1
161
+ ```
162
+
163
+ ## Citation
164
+
165
+ If you use this model in your research, please cite:
166
+
167
+ ```bibtex
168
+ Coming soon...
169
+ ```
170
+
171
+ ## License
172
+
173
+ This model is released under the same license as the base Llama-3-8B-Instruct model. Please refer to the [Llama 3 Community License](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct) for details.
174
+
175
+ ## Contact
176
+
177
+ For questions and support, please open an issue on the [GitHub repository](https://github.com/longyongchao/CopyPasteLLM).
178
 
179
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
 
181
+ **Note**: This model is designed for research and educational purposes. Please ensure responsible use and compliance with applicable laws and regulations.