Code Monkey home page Code Monkey logo

medalpaca's Introduction

medalpaca

medAlpaca: Finetuned Large Language Models for Medical Question Answering

Project Overview

MedAlpaca expands upon both Stanford Alpaca and AlpacaLoRA to offer an advanced suite of large language models specifically fine-tuned for medical question-answering and dialogue applications. Our primary objective is to deliver an array of open-source language models, paving the way for seamless development of medical chatbot solutions.

These models have been trained using a variety of medical texts, encompassing resources such as medical flashcards, wikis, and dialogue datasets. For more details on the data utilized, please consult the data section.

Getting Started

Create a new virtual environment, e.g. with conda

conda create -n medalpaca python>=3.9

Install the required packages:

pip install -r requirements.txt

Training of medAlpaca

training your alpaca

Memory Requirements

We have benchmarked the needed GPU memory as well as the approximate duration per epoch for finetuning LLaMA 7b on the Medical Meadow small dataset (~6000 Q/A pairs) on a single GPU:

Model 8bit trainig LoRA fp16 bf16 VRAM Used Gradient cktp Duration/epoch
LLaMA 7b True True True False 8.9 GB False 77:30
LLaMA 7b False True True False 18.8 GB False 14:30
LLaMA 7b False False True False OOM False -
LLaMA 7b False False False True 79.5 GB True 35:30
LLaMA 7b False False False False OOM True -

Train medAlpaca based on LLaMA

If you have access to the LLaMA or Alpaca weights you can finetune the model with the following command. Just replace <PATH_TO_LLAMA_WEIGHTS> with the folder containing you LLaMA or Alpaca weights.

python medalpaca/train.py \
    --model PATH_TO_LLAMA_WEIGHTS \
    --data_path medical_meadow_small.json \
    --output_dir 'output' \
    --train_in_8bit True \  
    --use_lora True \
    --bf16 True \
    --tf32 False \
    --fp16 False \
    --global_batch_size 128 \
    --per_device_batch_size 8 \

Per default the script performs mixed precision training.
You can toggle 8bit training with the train_in_8bit flag. While 8 bit training currently only works with use_lora True, however you can use LoRA without 8 bit training. It is also able to train other models such as facebook/opt-6.7 with the above script.

Data

Screenshot 2023-03-31 at 09 37 41

To ensure your cherished llamas and alpacas are well-fed and thriving, we have diligently gathered high-quality biomedical open-source datasets and transformed them into instruction tuning formats. We have dubbed this endeavor Medical Meadow. Medical Meadow currently encompasses roughly 1.5 million data points across a diverse range of tasks, including openly curated medical data transformed into Q/A pairs with OpenAI's gpt-3.5-turbo and a collection of established NLP tasks in the medical domain. Please note, that not all data is of the same quantitiy and quality and you may need tp subsample the data for training your own model. We will persistently update and refine the dataset, and we welcome everyone to contribute more 'grass' to Medical Meadow!

Data Overview

Name Source n n included in training
Medical Flashcards medalpaca/medical_meadow_medical_flashcards 33955 33955
Wikidoc medalpaca/medical_meadow_wikidoc 67704 10000
Wikidoc Patient Information medalpaca/medical_meadow_wikidoc_patient_information 5942 5942
Stackexchange academia medalpaca/medical_meadow_stack_exchange 40865 40865
Stackexchange biology medalpaca/medical_meadow_stack_exchange 27887 27887
Stackexchange fitness medalpaca/medical_meadow_stack_exchange 9833 9833
Stackexchange health medalpaca/medical_meadow_stack_exchange 7721 7721
Stackexchange bioinformatics medalpaca/medical_meadow_stack_exchange 5407 5407
USMLE Self Assessment Step 1 medalpaca/medical_meadow_usmle_self 119 92 (test only)
USMLE Self Assessment Step 2 medalpaca/medical_meadow_usmle_self 120 110 (test only)
USMLE Self Assessment Step 3 medalpaca/medical_meadow_usmle_self 135 122 (test only)
MEDIQA original, preprocessed 2208 2208
CORD-19 original, preprocessed 1056660 50000
MMMLU original, preprocessed 3787 3787
Pubmed Health Advice original, preprocessed 10178 10178
Pubmed Causal original, preprocessed 2446 2446
ChatDoctor original 215000 10000
OpenAssistant original 9209 9209

Data description

please refer to DATA_DESCRIPTION.md

Benchmarks

benchmarks

We are benchmarking all models on the USMLE self assessment, which is available at this link. Note, that we removed all questions with images, as our models are not multimodal.

Model Step1 Step2 Step3
LLaMA 7b 0.198 0.202 0.203
Alpaca 7b naive (weights) 0.275 0.266 0.293
Alpaca 7b LoRA 0.220 0.138 0.252
MedAlpaca 7b 0.297 0.312 0.398
MedAlpaca 7b LoRA 0.231 0.202 0.179
MedAlpaca 7b LoRA 8bit 0.231 0.241 0.211
ChatDoctor (7b) 0.187 0.185 0.148
LLaMA 13b 0.222 0.248 0.276
Alpaca 13b naive 0.319 0.312 0.301
MedAlpaca 13b 0.473 0.477 0.602
MedAlpaca 13b LoRA 0.250 0.255 0.255
MedAlpaca 13b LoRA 8bit 0.189 0.303 0.289
MedAlpaca 30b (still training) TBA TBA TBA
MedAlpaca 30b LoRA 8bit 0.315 0.327 0.361

We are continuously working on improving the training as well as our evaluation prompts. Expect this table to change quite a bit.

Access the models

Visit the zoo and have a look at our alpacas here: https://huggingface.co/medalpaca

It should be obvious, but the models provided on this platform are shared for research purposes only and should not be used in any healthcare applications or settings. While we are excited to showcase our experimental models, please be aware that they have not undergone extensive testing or validation, and their reliability cannot be guaranteed. We kindly ask you to exercise caution when using these models, and we appreciate your understanding as we continue to explore and develop this innovative technology.

Paper

chat-lama

@article{han2023medalpaca,
  title={MedAlpaca--An Open-Source Collection of Medical Conversational AI Models and Training Data},
  author={Han, Tianyu and Adams, Lisa C and Papaioannou, Jens-Michalis and Grundmann, Paul and Oberhauser, Tom and L{\"o}ser, Alexander and Truhn, Daniel and Bressem, Keno K},
  journal={arXiv preprint arXiv:2304.08247},
  year={2023}
}

medalpaca's People

Contributors

hyesunyun avatar kbressem avatar peterhan91 avatar r-kellerm avatar rayrayraykk avatar shan23chen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

medalpaca's Issues

Unable to Load USMLE datasets

Hi, thanks for the repo!

I can't seem to load the USMLE datasets used in eval.

2 of three links provided in the readme don't seem to work (USMLE Self Assessment Step 2, USMLE Self Assessment Step 3).

The first link works, but fails when trying to load from hugging face as follows:

from datasets import load_dataset
part1 = load_dataset('medalpaca/medical_meadow_usmle_self_assessment',split='train')

Error:

Downloading and preparing dataset json/medalpaca--medical_meadow_usmle_self_assessment to /root/.cache/huggingface/datasets/medalpaca___json/medalpaca--medical_meadow_usmle_self_assessment-333492f3a84c0741/0.0.0/e347ab1c932092252e717ff3f949105a4dd28b27e842dd53157d2f72e276c2e4...
Downloading data files: 100%
1/1 [00:00<00:00, 63.10it/s]
Extracting data files: 100%
1/1 [00:00<00:00, 41.63it/s]
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /usr/local/lib/python3.10/dist-packages/datasets/builder.py:1873 in _prepare_split_single        │
│                                                                                                  │
│   1870 │   │   │   │   │   │   │   storage_options=self._fs.storage_options,                     │
│   1871 │   │   │   │   │   │   │   embed_local_files=embed_local_files,                          │
│   1872 │   │   │   │   │   │   )                                                                 │
│ ❱ 1873 │   │   │   │   │   writer.write_table(table)                                             │
│   1874 │   │   │   │   │   num_examples_progress_update += len(table)                            │
│   1875 │   │   │   │   │   if time.time() > _time + config.PBAR_REFRESH_TIME_INTERVAL:           │
│   1876 │   │   │   │   │   │   _time = time.time()                                               │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/datasets/arrow_writer.py:568 in write_table              │
│                                                                                                  │
│   565 │   │   if self.pa_writer is None:                                                         │
│   566 │   │   │   self._build_writer(inferred_schema=pa_table.schema)                            │
│   567 │   │   pa_table = pa_table.combine_chunks()                                               │
│ ❱ 568 │   │   pa_table = table_cast(pa_table, self._schema)                                      │
│   569 │   │   if self.embed_local_files:                                                         │
│   570 │   │   │   pa_table = embed_table_storage(pa_table)                                       │
│   571 │   │   self._num_bytes += pa_table.nbytes                                                 │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/datasets/table.py:2290 in table_cast                     │
│                                                                                                  │
│   2287 │   │   table (`pyarrow.Table`): the casted table                                         │
│   2288 │   """                                                                                   │
│   2289 │   if table.schema != schema:                                                            │
│ ❱ 2290 │   │   return cast_table_to_schema(table, schema)                                        │
│   2291 │   elif table.schema.metadata != schema.metadata:                                        │
│   2292 │   │   return table.replace_schema_metadata(schema.metadata)                             │
│   2293 │   else:                                                                                 │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/datasets/table.py:2248 in cast_table_to_schema           │
│                                                                                                  │
│   2245 │                                                                                         │
│   2246 │   features = Features.from_arrow_schema(schema)                                         │
│   2247 │   if sorted(table.column_names) != sorted(features):                                    │
│ ❱ 2248 │   │   raise ValueError(f"Couldn't cast\n{table.schema}\nto\n{features}\nbecause column  │
│   2249 │   arrays = [cast_array_to_feature(table[name], feature) for name, feature in features.  │
│   2250 │   return pa.Table.from_arrays(arrays, schema=schema)                                    │
│   2251                                                                                           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: Couldn't cast
image_url: string
no: int64
options: struct<A: string, B: string, C: string, D: string, E: string, F: string, G: string, H: string, I: string>
  child 0, A: string
  child 1, B: string
  child 2, C: string
  child 3, D: string
  child 4, E: string
  child 5, F: string
  child 6, G: string
  child 7, H: string
  child 8, I: string
question: string
image: string
to
{'step1': Sequence(feature=Value(dtype='int64', id=None), length=-1, id=None), 'step2': 
Sequence(feature=Value(dtype='int64', id=None), length=-1, id=None), 'step3': Sequence(feature=Value(dtype='int64',
id=None), length=-1, id=None)}
because column names don't match

The above exception was the direct cause of the following exception:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <cell line: 2>:2                                                                              │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/datasets/load.py:1797 in load_dataset                    │
│                                                                                                  │
│   1794 │   try_from_hf_gcs = path not in _PACKAGED_DATASETS_MODULES                              │
│   1795 │                                                                                         │
│   1796 │   # Download and prepare data                                                           │
│ ❱ 1797 │   builder_instance.download_and_prepare(                                                │
│   1798 │   │   download_config=download_config,                                                  │
│   1799 │   │   download_mode=download_mode,                                                      │
│   1800 │   │   verification_mode=verification_mode,                                              │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/datasets/builder.py:890 in download_and_prepare          │
│                                                                                                  │
│    887 │   │   │   │   │   │   │   prepare_split_kwargs["max_shard_size"] = max_shard_size       │
│    888 │   │   │   │   │   │   if num_proc is not None:                                          │
│    889 │   │   │   │   │   │   │   prepare_split_kwargs["num_proc"] = num_proc                   │
│ ❱  890 │   │   │   │   │   │   self._download_and_prepare(                                       │
│    891 │   │   │   │   │   │   │   dl_manager=dl_manager,                                        │
│    892 │   │   │   │   │   │   │   verification_mode=verification_mode,                          │
│    893 │   │   │   │   │   │   │   **prepare_split_kwargs,                                       │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/datasets/builder.py:985 in _download_and_prepare         │
│                                                                                                  │
│    982 │   │   │                                                                                 │
│    983 │   │   │   try:                                                                          │
│    984 │   │   │   │   # Prepare split will record examples associated to the split              │
│ ❱  985 │   │   │   │   self._prepare_split(split_generator, **prepare_split_kwargs)              │
│    986 │   │   │   except OSError as e:                                                          │
│    987 │   │   │   │   raise OSError(                                                            │
│    988 │   │   │   │   │   "Cannot find data file. "                                             │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/datasets/builder.py:1746 in _prepare_split               │
│                                                                                                  │
│   1743 │   │   │   gen_kwargs = split_generator.gen_kwargs                                       │
│   1744 │   │   │   job_id = 0                                                                    │
│   1745 │   │   │   with pbar:                                                                    │
│ ❱ 1746 │   │   │   │   for job_id, done, content in self._prepare_split_single(                  │
│   1747 │   │   │   │   │   gen_kwargs=gen_kwargs, job_id=job_id, **_prepare_split_args           │
│   1748 │   │   │   │   ):                                                                        │
│   1749 │   │   │   │   │   if done:                                                              │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/datasets/builder.py:1891 in _prepare_split_single        │
│                                                                                                  │
│   1888 │   │   │   # Ignore the writer's error for no examples written to the file if this erro  │
│   1889 │   │   │   if isinstance(e, SchemaInferenceError) and e.__context__ is not None:         │
│   1890 │   │   │   │   e = e.__context__                                                         │
│ ❱ 1891 │   │   │   raise DatasetGenerationError("An error occurred while generating the dataset  │
│   1892 │   │                                                                                     │
│   1893 │   │   yield job_id, True, (total_num_examples, total_num_bytes, writer._features, num_  │
│   1894                                                                                           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
DatasetGenerationError: An error occurred while generating the dataset

Can you assist with an example of how download the USMLE datasets?

training data

Hello,

I would like to retrain other LLMs based on your dataset. It seems like the link to DATA_DESCRIPTION.md has been broken.

Where can I get an access to your dataset?

Thanks

help to run!!!

these processes are ok,
conda create -n medalpaca python>=3.9
pip install -r requirements.txt

How should I run medAlpaca?

under demo folder: I am running python3 app.py
port 500 opens without any problems, but when I type something in "medAlpaca" I get no response.
Thank you.

is this script compatible with flan-t5?

Is the training script compatible with flan-t5, like changing the model name to google/flan-t5-xxl, will it work?

On my task I found flan-t5 models work much better than llama and want to see if fine-tuning can improve it more.

Thanks

Error loading 7B weights for medAlpaca

Hi!

I've been trying to run the medAlpaca training script based on the example given in the README.md.

However, I get this error when I load the 7B model :
bias is on the meta device, we need a value to put in on 0

What might be the reason behind this error? And how do we fix this?

Thanks!

System configuration:

GPU : NVIDIA RTX 3080 Ti 24 GB
RAM : 64 GB

Running medalpaca/train.py in a virtual environment; all dependencies installed using requirements.txt provided.

Cant Load File medical_meadow_small.json

Please check again on your training code sample.

from datasets import load_dataset

data = load_dataset("json",data_files="/kaggle/working/medAlpaca/medical_meadow_small.json")

---ERROR---
File /opt/conda/lib/python3.10/site-packages/datasets/packaged_modules/json/json.py:150, in Json._generate_tables(self, files)
145 except json.JSONDecodeError:
146 raise e
147 raise ValueError(
148 f"Not able to read records in the JSON file at {file}. "
149 f"You should probably indicate the field of the JSON file containing your records. "
--> 150 f"This JSON file contain the following fields: {str(list(dataset.keys()))}. "
151 f"Select the correct one and provide it as field='XXX' to the dataset loading method. "
152 ) from None
153 # Uncomment for debugging (will print the Arrow table size and elements)
154 # logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
155 # logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
156 yield (file_idx, batch_idx), self._cast_classlabels(pa_table)

AttributeError: 'list' object has no attribute 'keys'

NotImplementedError: Cannot copy out of meta tensor; no data!

Hello all,

I am trying to train using alpaca weights and the provided json dataset on a RTX 3090 with the command

python medalpaca/train.py \
    --model /path/to/alpaca-7b \
    --data_path medical_meadow_small.json \
    --output_dir 'output' \
    --train_in_8bit False \
    --use_lora False \
    --bf16 False \
    --tf32 False \
    --fp16 True \
    --global_batch_size 128 \
    --per_device_batch_size 4

but encounter the error

NotImplementedError: Cannot copy out of meta tensor; no data!

Training works fine if use_lora is True.

Anyone knows how to solve this problem? Thanks 🤗


Logs

2023-05-10 19:44:01.524862: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-05-10 19:44:01.992637: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT

===================================BUG REPORT===================================
Welcome to bitsandbytes. For bug reports, please run

python -m bitsandbytes

 and submit this information together with your error trace to: https://github.com/TimDettmers/bitsandbytes/issues
================================================================================
bin /home/x/.local/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda117.so
/home/x/.local/lib/python3.10/site-packages/bitsandbytes/cuda_setup/main.py:145: UserWarning: Found duplicate ['libcudart.so', 'libcudart.so.11.0', 'libcudart.so.12.0'] files: {PosixPath('/opt/anaconda3/envs/medalpaca/lib/libcudart.so'), PosixPath('/opt/anaconda3/envs/medalpaca/lib/libcudart.so.11.0')}.. We'll flip a coin and try one of these, in order to fail forward.
Either way, this might cause trouble in the future:
If you get `CUDA error: invalid device function` errors, the above might be the cause and the solution is to make sure only one ['libcudart.so', 'libcudart.so.11.0', 'libcudart.so.12.0'] in the paths that we search based on your env.
  warn(msg)
CUDA SETUP: CUDA runtime path found: /opt/anaconda3/envs/medalpaca/lib/libcudart.so
CUDA SETUP: Highest compute capability among GPUs detected: 8.6
CUDA SETUP: Detected CUDA version 117
CUDA SETUP: Loading binary /home/x/.local/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda117.so...
WARNING:datasets.builder:Found cached dataset json (/home/x/.cache/huggingface/datasets/json/default-f720834aba59ff0a/0.0.0/e347ab1c932092252e717ff3f949105a4dd28b27e842dd53157d2f72e276c2e4)
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 1145.98it/s]
WARNING:datasets.arrow_dataset:Loading cached split indices for dataset at /home/x/.cache/huggingface/datasets/json/default-f720834aba59ff0a/0.0.0/e347ab1c932092252e717ff3f949105a4dd28b27e842dd53157d2f72e276c2e4/cache-0d7eb55a8148f5f0.arrow and /home/x/.cache/huggingface/datasets/json/default-f720834aba59ff0a/0.0.0/e347ab1c932092252e717ff3f949105a4dd28b27e842dd53157d2f72e276c2e4/cache-378aa479480a6538.arrow
WARNING:datasets.arrow_dataset:Loading cached processed dataset at /home/x/.cache/huggingface/datasets/json/default-f720834aba59ff0a/0.0.0/e347ab1c932092252e717ff3f949105a4dd28b27e842dd53157d2f72e276c2e4/cache-4c32985cd8b5899a.arrow
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮                                                     
│ /medAlpaca/medalpaca/train.py:286 in <module>                                │
│                                                                                                  │
│   283                                                                                            │
│   284                                                                                            │
│   285 if __name__ == "__main__":                                                                 │
│ ❱ 286 │   fire.Fire(main)                                                                        │
│   287                                                                                            │
│                                                                                                  │
│ /home/x/.local/lib/python3.10/site-packages/fire/core.py:141 in Fire                         │
│                                                                                                  │
│   138 │   context.update(caller_globals)                                                         │
│   139 │   context.update(caller_locals)                                                          │
│   140                                                                                            │
│ ❱ 141   component_trace = _Fire(component, args, parsed_flag_args, context, name)                │
│   142                                                                                            │
│   143   if component_trace.HasError():                                                           │
│   144 │   _DisplayError(component_trace)                                                         │
│                                                                                                  │
│ /home/x/.local/lib/python3.10/site-packages/fire/core.py:475 in _Fire                        │
│                                                                                                  │
│   472 │     is_class = inspect.isclass(component)                                                │
│   473 │                                                                                          │
│   474 │     try:                                                                                 │
│ ❱ 475 │   │   component, remaining_args = _CallAndUpdateTrace(                                   │
│   476 │   │   │   component,                                                                     │
│   477 │   │   │   remaining_args,                                                                │
│   478 │   │   │   component_trace,                                                               │
│                                                                                                  │
│ /home/x/.local/lib/python3.10/site-packages/fire/core.py:691 in _CallAndUpdateTrace          │
│                                                                                                  │
│   688 │   loop = asyncio.get_event_loop()                                                        │
│   689 │   component = loop.run_until_complete(fn(*varargs, **kwargs))                            │
│   690   else:                                                                                    │
│ ❱ 691 │   component = fn(*varargs, **kwargs)                                                     │
│   692                                                                                            │
│   693   if treatment == 'class':                                                                 │
│   694 │   action = trace.INSTANTIATED_CLASS                                                      │
│                                                                                                  │
│ /medAlpaca/medalpaca/train.py:254 in main                                    │
│                                                                                                  │
│   251 │   │   **kwargs                                                                           │
│   252 │   )                                                                                      │
│   253 │                                                                                          │
│ ❱ 254 │   trainer = Trainer(                                                                     │
│   255 │   │   model=model,                                                                       │
│   256 │   │   train_dataset=data["train"],                                                       │
│   257 │   │   eval_dataset=data["test"] if val_set_size > 0 else None,                           │
│                                                                                                  │
│ /home/x/.local/lib/python3.10/site-packages/transformers/trainer.py:499 in __init__          │
│                                                                                                  │
│    496 │   │   self.tokenizer = tokenizer                                                        │
│    497 │   │                                                                                     │
│    498 │   │   if self.place_model_on_device and not getattr(model, "is_loaded_in_8bit", False)  │
│ ❱  499 │   │   │   self._move_model_to_device(model, args.device)                                │
│    500 │   │                                                                                     │
│    501 │   │   # Force n_gpu to 1 to avoid DataParallel as MP will manage the GPUs               │
│    502 │   │   if self.is_model_parallel:                                                        │
│                                                                                                  │
│ /home/x/.local/lib/python3.10/site-packages/transformers/trainer.py:741 in                   │
│ _move_model_to_device                                                                            │
│                                                                                                  │
│    738 │   │   self.callback_handler.remove_callback(callback)                                   │
│    739 │                                                                                         │
│    740 │   def _move_model_to_device(self, model, device):                                       │
│ ❱  741 │   │   model = model.to(device)                                                          │
│    742 │   │   # Moving a model to an XLA device disconnects the tied weights, so we have to re  │
│    743 │   │   if self.args.parallel_mode == ParallelMode.TPU and hasattr(model, "tie_weights")  │
│    744 │   │   │   model.tie_weights()                                                           │
│                                                                                                  │
│ /home/x/.local/lib/python3.10/site-packages/transformers/modeling_utils.py:1886 in to        │
│                                                                                                  │
│   1883 │   │   │   │   " model has already been set to the correct devices and casted to the co  │
│   1884 │   │   │   )                                                                             │
│   1885 │   │   else:                                                                             │
│ ❱ 1886 │   │   │   return super().to(*args, **kwargs)                                            │
│   1887 │                                                                                         │
│   1888 │   def half(self, *args):                                                                │
│   1889 │   │   # Checks if the model has been loaded in 8-bit                                    │
│                                                                                                  │
│ /home/x/.local/lib/python3.10/site-packages/torch/nn/modules/module.py:1145 in to            │
│                                                                                                  │
│   1142 │   │   │   │   │   │   │   non_blocking, memory_format=convert_to_format)                │
│   1143 │   │   │   return t.to(device, dtype if t.is_floating_point() or t.is_complex() else No  │
│   1144 │   │                                                                                     │
│ ❱ 1145 │   │   return self._apply(convert)                                                       │
│   1146 │                                                                                         │
│   1147 │   def register_full_backward_pre_hook(                                                  │
│   1148 │   │   self,                                                                             │
│                                                                                                  │
│ /home/x/.local/lib/python3.10/site-packages/torch/nn/modules/module.py:797 in _apply         │
│                                                                                                  │
│    794 │                                                                                         │
│    795 │   def _apply(self, fn):                                                                 │
│    796 │   │   for module in self.children():                                                    │
│ ❱  797 │   │   │   module._apply(fn)                                                             │
│    798 │   │                                                                                     │
│    799 │   │   def compute_should_use_set_data(tensor, tensor_applied):                          │
│    800 │   │   │   if torch._has_compatible_shallow_copy_type(tensor, tensor_applied):           │
│                                                                                                  │
│ /home/x/.local/lib/python3.10/site-packages/torch/nn/modules/module.py:797 in _apply         │
│                                                                                                  │
│    794 │                                                                                         │
│    795 │   def _apply(self, fn):                                                                 │
│    796 │   │   for module in self.children():                                                    │
│ ❱  797 │   │   │   module._apply(fn)                                                             │
│    798 │   │                                                                                     │
│    799 │   │   def compute_should_use_set_data(tensor, tensor_applied):                          │
│    800 │   │   │   if torch._has_compatible_shallow_copy_type(tensor, tensor_applied):           │
│                                                                                                  │
│ /home/x/.local/lib/python3.10/site-packages/torch/nn/modules/module.py:797 in _apply         │
│                                                                                                  │
│    794 │                                                                                         │
│    795 │   def _apply(self, fn):                                                                 │
│    796 │   │   for module in self.children():                                                    │
│ ❱  797 │   │   │   module._apply(fn)                                                             │
│    798 │   │                                                                                     │
│    799 │   │   def compute_should_use_set_data(tensor, tensor_applied):                          │
│    800 │   │   │   if torch._has_compatible_shallow_copy_type(tensor, tensor_applied):           │
│                                                                                                  │
│ /home/x/.local/lib/python3.10/site-packages/torch/nn/modules/module.py:797 in _apply         │
│                                                                                                  │
│    794 │                                                                                         │
│    795 │   def _apply(self, fn):                                                                 │
│    796 │   │   for module in self.children():                                                    │
│ ❱  797 │   │   │   module._apply(fn)                                                             │
│    798 │   │                                                                                     │
│    799 │   │   def compute_should_use_set_data(tensor, tensor_applied):                          │
│    800 │   │   │   if torch._has_compatible_shallow_copy_type(tensor, tensor_applied):           │
│                                                                                                  │
│ /home/x/.local/lib/python3.10/site-packages/torch/nn/modules/module.py:797 in _apply         │
│                                                                                                  │
│    794 │                                                                                         │
│    795 │   def _apply(self, fn):                                                                 │
│    796 │   │   for module in self.children():                                                    │
│ ❱  797 │   │   │   module._apply(fn)                                                             │
│    798 │   │                                                                                     │
│    799 │   │   def compute_should_use_set_data(tensor, tensor_applied):                          │
│    800 │   │   │   if torch._has_compatible_shallow_copy_type(tensor, tensor_applied):           │
│                                                                                                  │
│ /home/x/.local/lib/python3.10/site-packages/torch/nn/modules/module.py:820 in _apply         │
│                                                                                                  │
│    817 │   │   │   # track autograd history of `param_applied`, so we have to use                │
│    818 │   │   │   # `with torch.no_grad():`                                                     │
│    819 │   │   │   with torch.no_grad():                                                         │
│ ❱  820 │   │   │   │   param_applied = fn(param)                                                 │
│    821 │   │   │   should_use_set_data = compute_should_use_set_data(param, param_applied)       │
│    822 │   │   │   if should_use_set_data:                                                       │
│    823 │   │   │   │   param.data = param_applied                                                │
│                                                                                                  │
│ /home/x/.local/lib/python3.10/site-packages/torch/nn/modules/module.py:1143 in convert       │
│                                                                                                  │
│   1140 │   │   │   if convert_to_format is not None and t.dim() in (4, 5):                       │
│   1141 │   │   │   │   return t.to(device, dtype if t.is_floating_point() or t.is_complex() els  │
│   1142 │   │   │   │   │   │   │   non_blocking, memory_format=convert_to_format)                │
│ ❱ 1143 │   │   │   return t.to(device, dtype if t.is_floating_point() or t.is_complex() else No  │
│   1144 │   │                                                                                     │
│   1145 │   │   return self._apply(convert)                                                       │
│   1146                                                                                           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
NotImplementedError: Cannot copy out of meta tensor; no data!

Packages

absl-py==1.4.0
accelerate==0.18.0
addict==2.4.0
aenum==3.1.12
aiodns==3.0.0
aiofiles==23.1.0
aiohttp==3.8.4
aiohttp-retry==2.8.3
aiopg==1.4.0
aiosignal==1.3.1
aleph-alpha-client==3.0.0
altair==4.2.2
anthropic==0.2.6
antlr4-python3-runtime==4.9.3
anyio==3.6.2
appdirs==1.4.4
asttokens==2.2.1
astunparse==1.6.3
async-generator==1.10
async-timeout==4.0.2
attrs==23.1.0
Authlib==1.2.0
azure-cognitiveservices-speech==1.27.0
backcall==0.2.0
backoff==2.2.1
basicsr==1.4.2
bitsandbytes==0.38.1
black==23.3.0
bleach==6.0.0
blendmodes==2022
blis==0.7.9
boltons==23.0.0
boto3==1.26.109
botocore==1.29.109
cachetools==5.3.0
captcha-solver==0.1.5
catalogue==2.0.8
certifi==2022.12.7
cffi==1.15.1
cfgv==3.3.1
charset-normalizer==3.1.0
chromadb==0.3.21
clean-fid==0.1.29
click==8.1.3
click-log==0.4.0
clickhouse-connect==0.5.23
clip @ git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1
cmake==3.26.1
cohere==4.1.4
confection==0.0.4
contourpy==1.0.7
croniter==1.3.14
curl-cffi==0.5.5
cycler==0.11.0
cymem==2.0.7
dataclasses-json==0.5.7
datasets==2.12.0
decorator==5.1.1
deeplake==3.2.15
Deprecated==1.2.13
deprecation==2.1.0
dill==0.3.6
discord==2.2.3
discord.py==2.2.3
diskcache==5.6.1
distlib==0.3.6
dotty-dict==1.3.1
duckdb==0.7.1
duckduckgo-search==2.9.3
EbookLib==0.18
einops==0.4.1
elastic-transport==8.4.0
elasticsearch==8.7.0
email-validator==2.0.0.post2
en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.5.0/en_core_web_sm-3.5.0-py3-none-any.whl
entrypoints==0.4
exceptiongroup==1.1.1
executing==1.2.0
exponent-server-sdk==2.0.0
facexlib==0.2.5
fairscale==0.4.13
faiss-cpu==1.7.3
fake-useragent==1.1.3
fastapi==0.94.0
ffmpy==0.3.0
filelock==3.11.0
filterpy==1.4.5
fire==0.5.0
Flask-Cors==3.0.10
flatbuffers==23.3.3
font-roboto==0.0.1
fonts==0.0.3
fonttools==4.39.3
frozenlist==1.3.3
fsspec==2023.4.0
ftfy==6.1.1
gast==0.5.3
gdown==4.7.1
gfpgan==1.3.8
gitdb==4.0.10
GitPython==3.1.30
google-api-core==2.11.0
google-api-python-client==2.84.0
google-auth==2.17.2
google-auth-httplib2==0.1.0
google-auth-oauthlib==1.0.0
google-pasta==0.2.0
google-search-results==2.4.2
googleapis-common-protos==1.59.0
GoogleBard==1.0.0
gotrue==1.0.1
gpt4free==1.0.2
gradio==3.28.3
gradio_client==0.2.1
greenlet==2.0.1
grpcio==1.53.0
grpcio-tools==1.53.0
gTTS==2.3.2
gunicorn==20.1.0
h11==0.12.0
h5py==3.8.0
hnswlib==0.7.0
html2text==2020.1.16
httpcore==0.15.0
httptools==0.5.0
httpx==0.23.3
hub==3.0.1
huggingface-hub==0.13.4
humbug==0.3.1
identify==2.5.24
idna==2.10
imageio==2.27.0
inflection==0.5.1
InstructorEmbedding==1.0.0
invoke==1.7.3
ipython==8.13.2
jaraco.context==4.3.0
jax==0.4.8
jedi==0.18.2
Jinja2==3.1.2
jmespath==1.0.1
joblib==1.2.0
jsonlines==3.1.0
jsonmerge==1.8.0
jsonschema==4.17.3
keras==2.12.0
kiwisolver==1.4.4
kornia==0.6.7
langchain==0.0.136
langcodes==3.3.0
langid==1.1.6
lark==1.1.2
lazy_loader==0.2
libclang==16.0.0
lightning-utilities==0.8.0
linkify-it-py==2.0.0
lit==16.0.0
llama-index==0.5.11
llvmlite==0.39.1
lmdb==1.4.1
loguru==0.6.0
lpips==0.1.4
manifest-ml==0.1.2
Markdown==3.4.3
markdown-it-py==2.2.0
MarkupSafe==2.1.2
marshmallow==3.19.0
marshmallow-enum==1.5.1
matplotlib==3.7.1
matplotlib-inline==0.1.6
mdit-py-plugins==0.3.3
mdurl==0.1.2
ml-dtypes==0.0.4
mpmath==1.3.0
multidict==6.0.4
multiprocess==0.70.14
murmurhash==1.0.9
mypy-extensions==1.0.0
names==0.3.0
netmiko==4.2.0
networkx==3.1
nlpcloud==1.0.40
nltk==3.8.1
nodeenv==1.7.0
nomic==1.1.6
ntc-templates==3.3.0
numba==0.56.4
numcodecs==0.11.0
numpy==1.24.3
nvidia-cublas-cu11==11.10.3.66
nvidia-cuda-cupti-cu11==11.7.101
nvidia-cuda-nvrtc-cu11==11.7.99
nvidia-cuda-runtime-cu11==11.7.99
nvidia-cudnn-cu11==8.5.0.96
nvidia-cufft-cu11==10.9.0.58
nvidia-curand-cu11==10.2.10.91
nvidia-cusolver-cu11==11.4.0.1
nvidia-cusparse-cu11==11.7.4.91
nvidia-nccl-cu11==2.14.3
nvidia-nvtx-cu11==11.7.91
omegaconf==2.2.3
open-clip-torch @ git+https://github.com/mlfoundations/open_clip.git@bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b
openai==0.27.4
openapi-schema-pydantic==1.2.4
opencv-python==4.7.0.72
opensearch-py==2.2.0
opt-einsum==3.3.0
orjson==3.8.10
outcome==1.2.0
packaging==23.0
pandas==2.0.1
paramiko==3.1.0
parso==0.8.3
pathos==0.3.0
pathspec==0.11.1
pathy==0.10.1
peft @ git+https://github.com/huggingface/peft.git@b1059b73aab9043b118ff19b0cf96263ea86248a
pexpect==4.8.0
pgvector==0.1.6
pickleshare==0.7.5
piexif==1.1.3
Pillow==9.5.0
pinecone-client==2.2.1
pip-review==1.3.0
pkginfo==1.9.6
platformdirs==3.2.0
playsound==1.2.2
playwright==1.33.0
postgrest==0.10.6
posthog==3.0.1
pox==0.3.2
ppft==1.7.6.6
pre-commit==3.3.1
preshed==3.0.8
procrastinate==0.27.0
prompt-toolkit==3.0.38
protobuf==3.20.3
psutil==5.9.5
psycopg2-binary==2.9.6
ptyprocess==0.7.0
pure-eval==0.2.2
pyarrow==11.0.0
pyasn1-modules==0.2.8
pycares==4.3.0
pycparser==2.21
pycryptodome==3.17
pydantic==1.10.7
pydeck==0.8.1b0
pyDeprecate==0.3.2
pydub==0.25.1
pyee==9.0.4
PyGithub==1.58.1
Pygments==2.14.0
PyJWT==2.6.0
pyllamacpp==1.0.7
pymailtm==1.1.1
Pympler==1.0.1
pyparsing==3.0.9
PyPasser==0.0.5
pypdf==3.7.1
PyPDF2==3.0.1
pyre-extensions==0.0.30
pyrsistent==0.19.3
pyserial==3.5
PySocks==1.7.1
python-dateutil==2.8.2
python-dotenv==1.0.0
python-git==2018.2.1
python-gitlab==3.13.0
python-http-client==3.3.7
python-multipart==0.0.6
python-semantic-release==7.33.2
pytorch-lightning==1.7.6
pytz==2023.3
pytz-deprecation-shim==0.1.0.post0
PyWavelets==1.4.1
PyYAML==6.0
qdrant-client==1.1.3
random-username==1.0.2
readme-renderer==37.3
realesrgan==0.3.0
realtime==1.0.0
redis==4.5.4
regex==2023.3.23
requests==2.30.0
requests-oauthlib==1.3.1
requests-toolbelt==0.10.1
resize-right==0.0.2
responses==0.18.0
rfc3986==1.5.0
rich==13.3.3
rsa==4.9
runpod==0.9.3
s3transfer==0.6.0
scikit-image==0.19.2
scikit-learn==1.2.2
scp==0.14.5
selenium==4.9.0
semantic-version==2.10.0
semver==2.13.0
Send2Trash==1.8.2
sendgrid==6.10.0
sentence-transformers==2.2.2
sentencepiece==0.1.99
six==1.16.0
smart-open==6.3.0
smmap==5.0.0
sniffio==1.3.0
spacy==3.5.1
spacy-legacy==3.0.12
spacy-loggers==1.0.4
SpeechRecognition==3.8.1
SQLAlchemy==1.4.47
sqlitedict==2.1.0
srsly==2.4.6
stack-data==0.6.2
starkbank-ecdsa==2.2.0
starlette==0.26.1
storage3==0.5.2
streamlit==1.21.0
StrEnum==0.4.10
supabase==1.0.3
supafunc==0.2.2
sympy==1.11.1
tb-nightly==2.13.0a20230413
tenacity==8.2.2
tensorboard==2.12.1
tensorboard-data-server==0.7.0
tensorboard-plugin-wit==1.8.1
tensorflow==2.12.0
tensorflow-estimator==2.12.0
tensorflow-hub==0.13.0
tensorflow-io-gcs-filesystem==0.32.0
tensorflow-text==2.12.0
termcolor==2.2.0
textfsm==1.1.3
thinc==8.1.9
threadpoolctl==3.1.0
tifffile==2023.3.21
tiktoken==0.3.3
timm==0.6.7
tls-client==0.2.1
tokenize-rt==5.0.0
tokenizers==0.13.3
toml==0.10.2
tomli==2.0.1
tomlkit==0.11.7
toolz==0.12.0
torch==2.0.0
torchdiffeq==0.2.3
torchmetrics==0.11.4
torchsde==0.2.5
torchvision==0.15.1
tqdm==4.65.0
tqdm-loggable==0.1.3
traitlets==5.9.0
trampoline==0.1.2
transformers @ git+https://github.com/huggingface/transformers.git@006da469dd5a465f4551f4245f780e3b1e92b76c
trio==0.22.0
trio-websocket==0.10.2
triton==2.0.0
tweepy==4.14.0
twine==3.8.0
TwoCaptcha==0.0.1
typer==0.7.0
typing-inspect==0.8.0
typing_extensions==4.5.0
tzdata==2023.3
tzlocal==4.3
uc-micro-py==1.0.1
ujson==5.7.0
undetected-chromedriver==3.1.7
uritemplate==4.1.1
urllib3==1.26.15
uvicorn==0.21.1
uvloop==0.17.0
validators==0.20.0
virtualenv==20.21.0
wasabi==1.1.1
watchdog==3.0.0
watchfiles==0.19.0
wcwidth==0.2.6
weaviate-client==3.15.5
webdriver-manager==3.8.6
websockets==10.4
wikipedia==1.4.0
wolframalpha==5.0.0
wonderwords==2.2.0
wrapt==1.15.0
xmltodict==0.13.0
xxhash==3.2.0
yapf==0.32.0
yarl==1.8.2
zstandard==0.21.0

Inference

How can i use this model for inference? I am using the HuggingFace implementation, however the model is unable to generate impressive answers to MCQ questions

Question about the medAlpaca init weight

Hi, I want to clarify the setting of medAlpaca. To my best of knowledge, the medAlpaca is initiate from Alpaca. However, have you ever try to use your dataset to directly ft Llama instead of Alpaca.

medAlpaca-lora-7b-8bit Checkout error

Hi @kbressem
I attempted to execute the MedAlpaca model from Hugging Face's source, but it appears that the MedAlpaca Hugging Face checkpoint has been removed. When using the 'pipeline' and 'AutoModel' with 'medalpaca/medalpaca-lora-7b-8bit,' I receive the error message: 'medalpaca/medalpaca-lora-7b-8bit does not appear to have a file named config.json. Checkout https://huggingface.co/medalpaca/medalpaca-lora-7b-8bit/main for available files.' Additionally, I've noticed that MedAlpaca doesn't work with the 'Hosted inference Hugging Face API.'

How can I resolve this issue?
Thanks a lot.

My suggestion for the UI

User interface for models:

Docker must be in the game

My suggestion for the UI:
web interface

  1. Admin page (open source, especially wordpress admin) where you can install and delete mods and everything else
  2. User registration page, user login page, and forum plugin.
    To ports 80 (http) and 443 (https)
    Thank you.

RecursionError: maximum recursion depth exceeded while calling a Python object

Hi,
I am trying to run the hugging face example of medalpaca-7b:

from transformers import pipeline

qa_pipeline = pipeline("question-answering", model="medalpaca/medalpaca-7b", tokenizer="medalpaca/medalpaca-7b")
question = "What are the symptoms of diabetes?"
context = "Diabetes is a metabolic disease that causes high blood sugar. The symptoms include increased thirst, frequent urination, and unexplained weight loss."
answer = qa_pipeline({"question": question, "context": context})
print(answer)

but I got the following errors:

File "/home/Users/luol/anaconda3/envs/medalpaca/lib/python3.10/site-packages/transformers/tokenization_utils_fast.py", line 250, in convert_tokens_to_ids
return self._convert_token_to_id_with_added_voc(tokens)
File "/home/Users/luol/anaconda3/envs/medalpaca/lib/python3.10/site-packages/transformers/tokenization_utils_fast.py", line 257, in _convert_token_to_id_with_added_voc
return self.unk_token_id
File "/home/Users/luol/anaconda3/envs/medalpaca/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 1155, in unk_token_id
return self.convert_tokens_to_ids(self.unk_token)
File "/home/Users/luol/anaconda3/envs/medalpaca/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 1035, in unk_token
return str(self._unk_token)
RecursionError: maximum recursion depth exceeded while calling a Python object

My transformers version is 4.30.0
Is the error caused by the transformers version? Thanks!

[Feature Request] Support InternLM

Dear medAlpaca developer,

Greetings! I am vansinhu, a community developer and volunteer at InternLM. Your work has been immensely beneficial to me, and I believe it can be effectively utilized in InternLM as well. Welcome to add Discord https://discord.gg/gF9ezcmtM3 . I hope to get in touch with you.

Best regards,
vansinhu

Question about running fine-tuned model

Not sure if this is the right location to ask

I have fine-tuned the model and have the corresponding model_adapter.bin / model_config.json files

How would I go about actually testing my model locally?

I have some test code but don't think it's working properly (it just repeated half of my question and cutoff):

from transformers import LlamaForCausalLM, LlamaTokenizer
from peft import PeftModel, PeftConfig
import torch

peft_model_id = "/mnt/d/output2"
config = PeftConfig.from_pretrained(peft_model_id)
model = LlamaForCausalLM.from_pretrained(config.base_model_name_or_path)
model = PeftModel.from_pretrained(model, peft_model_id)
tokenizer = LlamaTokenizer.from_pretrained(config.base_model_name_or_path)


device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = model.to(device)
model.eval()

inputs = tokenizer("What are the clinical differences between ciprofloxacin and levaquin?", return_tensors="pt")

with torch.no_grad():
    outputs = model.generate(input_ids=inputs["input_ids"].to("cuda"), max_new_tokens=10)
    print(tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0])

Compare to BioMedLM

Congrats on the interesting project and good results! I was wondering if you have considered adding a comparison or finetuning BioMedLM (available from HuggingFace) on your dataset. From their blogpost, they claim a score of 50.3% in MedQA-USMLE. It's not clear how this relates to your benchmark scores, also for USMLE.

Error running eval_usmle.py

Hello!

Thank you so much for the repo.

I am trying to run the eval_usmle.py after creating a conda environment and installing dependencies using requirements.txt.

When I get to the part of generating outputs in the Inferer, I get an error.

Here is the output:

Traceback (most recent call last):
  File "/scratch/yun.hy/clinical-llm-alignment/medAlpaca/eval/eval_usmle.py", line 177, in <module>
    fire.Fire(main)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/fire/core.py", line 475, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/fire/core.py", line 691, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/scratch/yun.hy/clinical-llm-alignment/medAlpaca/eval/eval_usmle.py", line 158, in main
    response = model(
  File "/scratch/yun.hy/clinical-llm-alignment/medAlpaca/eval/../medalpaca/inferer.py", line 161, in __call__
    generation_output = self.model.generate(
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/peft/peft_model.py", line 550, in generate
    return self.base_model.generate(**kwargs)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/transformers/generation/utils.py", line 1572, in generate
    return self.sample(
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/transformers/generation/utils.py", line 2619, in sample
    outputs = self(
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/accelerate/hooks.py", line 165, in new_forward
    output = old_forward(*args, **kwargs)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/transformers/models/llama/modeling_llama.py", line 689, in forward
    outputs = self.model(
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/accelerate/hooks.py", line 165, in new_forward
    output = old_forward(*args, **kwargs)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/transformers/models/llama/modeling_llama.py", line 579, in forward
    layer_outputs = decoder_layer(
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/accelerate/hooks.py", line 165, in new_forward
    output = old_forward(*args, **kwargs)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/transformers/models/llama/modeling_llama.py", line 293, in forward
    hidden_states, self_attn_weights, present_key_value = self.self_attn(
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/accelerate/hooks.py", line 165, in new_forward
    output = old_forward(*args, **kwargs)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/transformers/models/llama/modeling_llama.py", line 195, in forward
    query_states = self.q_proj(hidden_states).view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/accelerate/hooks.py", line 165, in new_forward
    output = old_forward(*args, **kwargs)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/peft/tuners/lora.py", line 421, in forward
    result += self.lora_B(self.lora_A(self.lora_dropout(x))) * self.scaling
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/accelerate/hooks.py", line 165, in new_forward
    output = old_forward(*args, **kwargs)
  File "/home/yun.hy/.conda/envs/medalpaca/lib/python3.9/site-packages/torch/nn/modules/linear.py", line 114, in forward
    return F.linear(input, self.weight, self.bias)
RuntimeError: expected scalar type Half but found Float

Have you encountered this error before? I found some things somewhere that it could be related to bitsandbytes and running on v100. I tried another GPU but still getting this issue.

Thanks!

Getting different scores for medalpaca 7B and medalpaca 13b

Hi there!

Great work with medalpaca! I was trying to reproduce your scores on the USMLE eval sets for medalpaca 7B and medalpaca 13B. However, when I run the notebook shared in #40, I'm getting the following scores:

scores

To double verify I also calculated the scores directly myself, by ignoring the questions with images and I'm getting the same scores as the notebook.

I ran the eval code as follows:

python eval_usmle.py     --model_name medalpaca/medalpaca-7b     --prompt_template ../medalpaca/prompt_templates/medalpaca.json    --base_model False     --peft False   --load_in_8bit False  --path_to_exams medical_meadow_usmle_self_assessment
python eval_usmle.py     --model_name medalpaca/medalpaca-13b     --prompt_template ../medalpaca/prompt_templates/medalpaca.json    --base_model False     --peft False   --load_in_8bit False  --path_to_exams medical_meadow_usmle_self_assessment

But I'm still seeing considerable differences. The medalpaca 7B is quite close to its reported scores on the github readme but not so for medalpaca-13B. Could you let me know if I might be doing something wrong on my side?

Thank you!

model.save_pretrained error

I tried to run the fine-tuning tutorial and however I got the error in the last step(save_pretrained).

I have 8 gpus in one node and it appeared that part of the saving is complete but about half of them showing error messages.

not sure this is because of memory or other issues, I google it but with no luck. help someone could help.

my code is below:
CUDA_LAUNCH_BLOCKING=1 torchrun --nproc_per_node=8 --master_port=9876 medalpaca/train.py
--model 'medalpaca/medalpaca-7b'
--data_path 'medical_meadow_small.json'
--output_dir './alpaca-7b'
--train_in_8bit False
--use_lora False
--bf16 False
--tf32 False
--fp16 True
--gradient_checkpointing True
--global_batch_size 256
--per_device_batch_size 4
--wandb_project 'medalpaca'
--prompt_template '/home/anpo/medAlpaca/medAlpaca/medalpaca/prompt_templates/medalpaca.json'
--use_wandb False

The error message below:

Traceback (most recent call last):
File "/home/anpo/medAlpaca/medAlpaca/medalpaca/train.py", line 285, in
fire.Fire(main)
File "/home/anpo/.conda/envs/medAlpaca/lib/python3.11/site-packages/fire/core.py", line 141, in Fire
component_trace = _Fire(component, args, parsed_flag_args, context, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/anpo/.conda/envs/medAlpaca/lib/python3.11/site-packages/fire/core.py", line 475, in _Fire
component, remaining_args = _CallAndUpdateTrace(
^^^^^^^^^^^^^^^^^^^^
File "/home/anpo/.conda/envs/medAlpaca/lib/python3.11/site-packages/fire/core.py", line 691, in _CallAndUpdateTrace
component = fn(*varargs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/anpo/medAlpaca/medAlpaca/medalpaca/train.py", line 281, in main
model.save_pretrained(output_dir)
File "/home/anpo/.conda/envs/medAlpaca/lib/python3.11/site-packages/transformers/modeling_utils.py", line 2376, in save_pretrained
safe_save_file(shard, os.path.join(save_directory, shard_file), metadata={"format": "pt"})
File "/home/anpo/.conda/envs/medAlpaca/lib/python3.11/site-packages/safetensors/torch.py", line 281, in save_file
serialize_file(_flatten(tensors), filename, metadata=metadata)
^^^^^^^^^^^^^^^^^
File "/home/anpo/.conda/envs/medAlpaca/lib/python3.11/site-packages/safetensors/torch.py", line 475, in _flatten
return {
^
File "/home/anpo/.conda/envs/medAlpaca/lib/python3.11/site-packages/safetensors/torch.py", line 479, in
"data": _tobytes(v, k),
^^^^^^^^^^^^^^
File "/home/anpo/.conda/envs/medAlpaca/lib/python3.11/site-packages/safetensors/torch.py", line 404, in _tobytes
tensor = tensor.to("cpu")
^^^^^^^^^^^^^^^^
RuntimeError: CUDA error: invalid argument
Compile with TORCH_USE_CUDA_DSA to enable device-side assertions.

Release Model?

Will you make MedAlpaca 13b model publicly available, and the possible 30b?Its performance has me excited.

Pin requirements

There seems to be a problem when installing the environment from the provided environment file, where the inference only runs on CPU not CUDA. Pinning the requirements could potentially solve this.

Error running medAlpaca in colab

Hello there.

I tried running the model in Colab, but got an error. Furthermore, I have connected a GPU device. Any help would be greatly appreciated.

Code:

!git clone https://github.com/kbressem/medAlpaca.git
%cd medAlpaca
!pip install -r requirements.txt

from medalpaca.inferer import Inferer

model = Inferer(
        model_name="medalpaca/medalapca-lora-7b-8bit",
        prompt_template="medalpaca/prompt_templates/medalpaca.json",
        base_model="decapoda-research/llama-7b-hf",
        peft=True,
        load_in_8bit=True,

Error message:

Loading checkpoint shards: 100%
33/33 [01:05<00:00, 2.06s/it]
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /usr/local/lib/python3.10/dist-packages/peft/utils/config.py:106 in from_pretrained              │
│                                                                                                  │
│   103 │   │   │   config_file = os.path.join(path, CONFIG_NAME)                                  │
│   104 │   │   else:                                                                              │
│   105 │   │   │   try:                                                                           │
│ ❱ 106 │   │   │   │   config_file = hf_hub_download(                                             │
│   107 │   │   │   │   │   pretrained_model_name_or_path, CONFIG_NAME, subfolder=subfolder, **k   │
│   108 │   │   │   │   )                                                                          │
│   109 │   │   │   except Exception:                                                              │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_validators.py:118 in _inner_fn    │
│                                                                                                  │
│   115 │   │   if check_use_auth_token:                                                           │
│   116 │   │   │   kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=ha   │
│   117 │   │                                                                                      │
│ ❱ 118 │   │   return fn(*args, **kwargs)                                                         │
│   119 │                                                                                          │
│   120 │   return _inner_fn  # type: ignore                                                       │
│   121                                                                                            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: hf_hub_download() got an unexpected keyword argument 'torch_dtype'

During handling of the above exception, another exception occurred:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <cell line: 3>:3                                                                              │
│                                                                                                  │
│ /content/medAlpaca/medalpaca/inferer.py:54 in __init__                                           │
│                                                                                                  │
│    51 │   │   │   │   "This would load the base model only"                                      │
│    52 │   │   │   )                                                                              │
│    53 │   │                                                                                      │
│ ❱  54 │   │   self.model = self._load_model(                                                     │
│    55 │   │   │   model_name = model_name,                                                       │
│    56 │   │   │   base_model = base_model or model_name,                                         │
│    57 │   │   │   load_in_8bit = load_in_8bit,                                                   │
│                                                                                                  │
│ /content/medAlpaca/medalpaca/inferer.py:94 in _load_model                                        │
│                                                                                                  │
│    91 │   │   )                                                                                  │
│    92 │   │                                                                                      │
│    93 │   │   if peft:                                                                           │
│ ❱  94 │   │   │   model = PeftModel.from_pretrained(                                             │
│    95 │   │   │   │   model,                                                                     │
│    96 │   │   │   │   model_id=model_name,                                                       │
│    97 │   │   │   │   torch_dtype=torch_dtype,                                                   │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/peft/peft_model.py:180 in from_pretrained                │
│                                                                                                  │
│    177 │   │                                                                                     │
│    178 │   │   # load the config                                                                 │
│    179 │   │   config = PEFT_TYPE_TO_CONFIG_MAPPING[                                             │
│ ❱  180 │   │   │   PeftConfig.from_pretrained(model_id, subfolder=kwargs.get("subfolder", None)  │
│    181 │   │   ].from_pretrained(model_id, subfolder=kwargs.get("subfolder", None), **kwargs)    │
│    182 │   │                                                                                     │
│    183 │   │   if (getattr(model, "hf_device_map", None) is not None) and len(                   │
│                                                                                                  │
│ /usr/local/lib/python3.10/dist-packages/peft/utils/config.py:110 in from_pretrained              │
│                                                                                                  │
│   107 │   │   │   │   │   pretrained_model_name_or_path, CONFIG_NAME, subfolder=subfolder, **k   │
│   108 │   │   │   │   )                                                                          │
│   109 │   │   │   except Exception:                                                              │
│ ❱ 110 │   │   │   │   raise ValueError(f"Can't find '{CONFIG_NAME}' at '{pretrained_model_name   │
│   111 │   │                                                                                      │
│   112 │   │   loaded_attributes = cls.from_json_file(config_file)                                │
│   113                                                                                            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: Can't find 'adapter_config.json' at 'medalpaca/medalapca-lora-7b-8bit'

error running the model in google colab

i get the following error when i try to use the sample code provided in the model card in google colab
the code

from transformers import pipeline
qa_pipeline = pipeline("question-answering", model="medalpaca/medalpaca-13b", tokenizer="medalpaca/medalpaca-13b")
question = "What are the symptoms of diabetes?"
context = "Diabetes is a metabolic disease that causes high blood sugar. The symptoms include increased thirst, frequent urination, and unexplained weight loss."
answer = qa_pipeline({"question": question, "context": context})
print(answer)

the error:

 
KeyError                                  Traceback (most recent call last)

[<ipython-input-6-936eb75f679c>](https://localhost:8080/#) in <cell line: 2>()
      1 from transformers import pipeline
----> 2 qa_pipeline = pipeline("question-answering", model="medalpaca/medalpaca-13b", tokenizer="medalpaca/medalpaca-13b")
      3 question = "What are the symptoms of diabetes?"
      4 context = "Diabetes is a metabolic disease that causes high blood sugar. The symptoms include increased thirst, frequent urination, and unexplained weight loss."
      5 answer = qa_pipeline({"question": question, "context": context})

2 frames

[/usr/local/lib/python3.9/dist-packages/transformers/models/auto/configuration_auto.py](https://localhost:8080/#) in __getitem__(self, key)
    621             return self._extra_content[key]
    622         if key not in self._mapping:
--> 623             raise KeyError(key)
    624         value = self._mapping[key]
    625         module_name = model_type_to_module_name(key)

KeyError: 'llama'

stackoverflow links missing

Hi, it seems the stackoverflow datasets are no longer accessable. May I ask what the situation is and if it's still possible to access those?
Thank you.

LLaMA 2

Thanks for sharing!

I was not sure if the training will work for LLaMA 2, instead of LLaMA?

How are numbers in the Benchmarks Table Calculated

So I can see in the eval script where the answers are generated and stored. I assume some calculation like num_correct/num_questions is done to get the results in the benchmarking table.

When computing if an answer is correct, do you simply check the starting letter of the answer using regex similiar to this or some more sophisticated logic?

HP Tuning

  • tune the LR
  • increase val batch size
  • tune dropout (0.2 in Instruct GPT) | most important
  • tune --lora_r 8 (rank, the bigger, the heavier the lora is (more params to tune)) maybe 16
  • tune --lora_alpha 16 (the smaller it is, the bigger the retraining amount)
  • less epochs (2-3, higher batch size)

medalpaca 13b outputs "OOO,O,O,O,O,O,O,O,O,O,O,"

Hi,

I tried it from huggingface using

from transformers import LlamaTokenizer, AutoModelForCausalLM
tokenizer = LlamaTokenizer.from_pretrained("medalpaca/medalpaca-13b")
model = AutoModelForCausalLM.from_pretrained("medalpaca/medalpaca-13b", device_map='auto')
input = 'SOAP note is a type of clinical note. please expand on that '
input_ids = tokenizer(input, return_tensors="pt").input_ids.to('cuda')
print(tokenizer.decode(model.generate(input_ids, max_length=50)[0]))

then the output is </s>SOAP note is a type of clinical note. please expand on that OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

with the corresponding ids tensor([ 2, 7791, 3301, 4443, 338, 263, 1134, 310, 24899, 936, 4443, 29889, 3113, 7985, 373, 393, 29871, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949, 29949], device='cuda:1')

Any clues?

Questions on USMLE questions

Hello!

I had some questions about USMLE dataset that was used for evaluation.
Based on the paper, it looks like you also use the MedQA - USMLE and also additional USMLE questions for training the model.

For the evaluation, do you check to make sure that the questions in the evaluation set (test set) are not duplicates of the training set?

Also, where could I download the USMLE step questions for the evaluation?
I see that this one is available on HuggingFace: https://huggingface.co/datasets/medalpaca/medical_meadow_usmle_self_assessment
However, it seems like this might be for training and not evaluating.

I would like to download the same version of the USMLE that you have used for the eval.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.