File size: 6,549 Bytes
22db95e
2f7faaa
05d984a
 
2f7faaa
05d984a
2f7faaa
05d984a
 
 
 
 
22db95e
2f7faaa
05d984a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75691ae
 
05d984a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f7faaa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05d984a
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
---
tags:
- physics
- cosmology
model-index:
- name: cosmosage_qa
  results: []
license: mit
language:
- en
pipeline_tag: text-generation
base_model: mistralai/Mistral-7B-v0.1
---

# cosmosage

Cosmosage is a natural-language cosmology assistant that can answer questions about cosmology.

cosmosage_v2 first underwent continued pretraining based on thousands of papers and textbooks, 
and was subsequently fine-tuned on synthetically-generated question-answer pairs. It is a full
chat model, though it excels in Q&A mode, where the model gives a single answer in response to 
a single question.

The code used to generate cosmosage_v2 is available at https://github.com/tijmen/cosmosage

## Usage

After downloading cosmosage_v2, the following example code can be used to ask questions:

```python
path_to_model = 'cosmosage_v2/'

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
device = "cuda"
model = AutoModelForCausalLM.from_pretrained(path_to_model).to(device)
tokenizer = AutoTokenizer.from_pretrained(path_to_model)
def ask_cosmosage(question):
    input_ids = torch.cat([
    tokenizer.encode("You are cosmosage, an AI programmed to be a cosmology expert. You answer the USER's question clearly in long form, always providing context. When appropriate, provide a reference.", return_tensors="pt"),
    torch.tensor([[28705]]),
    tokenizer.encode("USER:", add_special_tokens=False, return_tensors="pt"),
    tokenizer.encode(question, add_special_tokens=False, return_tensors="pt"),
    torch.tensor([[28705]]),
    tokenizer.encode("ASSISTANT:", add_special_tokens=False, return_tensors="pt")
    ], dim=-1).to(device)
    generated_ids = model.generate(input_ids, max_length=input_ids.shape[1] + 1000, do_sample=True)
    return tokenizer.decode(generated_ids[0], skip_special_tokens=True)```

## Comparison to cosmosage_v1

cosmosage_v2 is a more knowledgeable model than cosmosage_v1 due to being pretrained on the papers and
textbooks, rather than just on synthetically generated QA pairs. However, it continues to struggle with 
_reliability_. While many of its answers are factually accurate, some are not. The outputs of cosmosage 
(or any LLM) should not be trusted to be factual.

[<img src="https://raw.githubusercontent.com/OpenAccess-AI-Collective/axolotl/main/image/axolotl-badge-web.png" alt="Built with Axolotl" width="200" height="32"/>](https://github.com/OpenAccess-AI-Collective/axolotl)
<details><summary>See axolotl config</summary>

axolotl version: `0.4.0`
```yaml
base_model: /workspace/output/cosmosage_base/
model_type: MistralForCausalLM
tokenizer_type: LlamaTokenizer
is_mistral_derived_model: true

load_in_8bit: false
load_in_4bit: false
strict: false

datasets:
  - path: /workspace/input/datasets/qa_tune/arxiv_metadata_qa3.jsonl
    type: sharegpt
  - path: /workspace/input/datasets/qa_tune/arxiv_refined_qa.jsonl
    type: sharegpt
  - path: /workspace/input/datasets/qa_tune/arxiv_summary3.jsonl
    type: sharegpt
  - path: /workspace/input/datasets/qa_tune/cosmology_qa.jsonl
    type: alpaca_chat.load_qa 
  - path: /workspace/input/datasets/qa_tune/openhermes2_5.jsonl
    type: sharegpt
  - path: /workspace/input/datasets/qa_tune/cosmology_textbooks_qa.jsonl
    type: alpaca_chat.load_qa 
  - path: /workspace/input/datasets/qa_tune/physics_astro_qa.jsonl
    type: alpaca_chat.load_qa 

dataset_prepared_path: /workspace/output/qa_tune_prepared
val_set_size: 0.001
output_dir: /workspace/output/cosmosage_qa

chat_template: inst

adapter: 
lora_model_dir:

sequence_len: 4096
sample_packing: true
pad_to_sequence_len: true

lora_r:
lora_alpha:
lora_dropout:
lora_target_modules:
lora_target_linear: 
lora_fan_in_fan_out:

seed: 702

wandb_project:
wandb_entity:
wandb_watch:
wandb_name:
wandb_log_model:

gradient_accumulation_steps: 1
micro_batch_size: 4
num_epochs: 2.0
optimizer: adamw_torch
lr_scheduler: linear
learning_rate: 0.000002
max_grad_norm: 3.0

train_on_inputs: false
group_by_length: false
bf16: true
fp16: false 
tf32: false

gradient_checkpointing: true
early_stopping_patience:
resume_from_checkpoint:
local_rank:
logging_steps: 1
xformers_attention:
flash_attention: true

warmup_steps: 100
eval_steps: 0.05
eval_table_size:
eval_table_max_new_tokens: 128
saves_per_epoch: 1
save_total_limit: 2
debug:
deepspeed: /workspace/axolotl/deepspeed_configs/zero1.json
weight_decay:
fsdp:
fsdp_config:
special_tokens:
  bos_token: "<s>"
  eos_token: "</s>"
  unk_token: "<unk>"

ddp_timeout: 7200000

```

</details><br>

# workspace/output/cosmosage_qa

This model was trained from scratch on the None dataset.
It achieves the following results on the evaluation set:
- Loss: 0.5673

## Model description

More information needed

## Intended uses & limitations

More information needed

## Training and evaluation data

More information needed

## Training procedure

### Training hyperparameters

The following hyperparameters were used during training:
- learning_rate: 2e-06
- train_batch_size: 4
- eval_batch_size: 4
- seed: 702
- distributed_type: multi-GPU
- num_devices: 4
- total_train_batch_size: 16
- total_eval_batch_size: 16
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
- lr_scheduler_type: linear
- lr_scheduler_warmup_steps: 100
- num_epochs: 2.0

### Training results

| Training Loss | Epoch | Step  | Validation Loss |
|:-------------:|:-----:|:-----:|:---------------:|
| 1.1004        | 0.0   | 1     | 1.1450          |
| 0.7343        | 0.1   | 909   | 0.7093          |
| 0.697         | 0.2   | 1818  | 0.6630          |
| 0.6386        | 0.3   | 2727  | 0.6380          |
| 0.5687        | 0.4   | 3636  | 0.6212          |
| 0.5857        | 0.5   | 4545  | 0.6083          |
| 0.6161        | 0.6   | 5454  | 0.5986          |
| 0.522         | 0.7   | 6363  | 0.5894          |
| 0.5563        | 0.8   | 7272  | 0.5825          |
| 0.6176        | 0.9   | 8181  | 0.5766          |
| 0.5948        | 1.0   | 9090  | 0.5719          |
| 0.4269        | 1.08  | 9999  | 0.5817          |
| 0.4858        | 1.18  | 10908 | 0.5796          |
| 0.4909        | 1.28  | 11817 | 0.5765          |
| 0.4325        | 1.38  | 12726 | 0.5746          |
| 0.4037        | 1.48  | 13635 | 0.5720          |
| 0.507         | 1.58  | 14544 | 0.5706          |
| 0.4778        | 1.68  | 15453 | 0.5697          |
| 0.4599        | 1.78  | 16362 | 0.5683          |
| 0.4515        | 1.88  | 17271 | 0.5673          |


### Framework versions

- Transformers 4.38.0.dev0
- Pytorch 2.0.1+cu118
- Datasets 2.17.0
- Tokenizers 0.15.0