Quellcode durchsuchen

Remove LLaMA download code, as a precaution

Eric Wang vor 3 Jahren
Ursprung
Commit
72aabcb5a4
5 geänderte Dateien mit 31 neuen und 12 gelöschten Zeilen
  1. 4 1
      .gitignore
  2. 7 2
      export_hf_checkpoint.py
  3. 7 2
      export_state_dict_checkpoint.py
  4. 6 4
      finetune.py
  5. 7 3
      generate.py

+ 4 - 1
.gitignore

@@ -7,4 +7,7 @@ minimal-llama**
 upload.py
 lora-**
 *ckpt
-wandb
+wandb
+evaluate.py
+test_data.json
+todo.txt

+ 7 - 2
export_hf_checkpoint.py

@@ -11,10 +11,15 @@ assert (
 ), "LLaMA is now in HuggingFace's main branch.\nPlease reinstall it: pip uninstall transformers && pip install git+https://github.com/huggingface/transformers.git"
 from transformers import LlamaTokenizer, LlamaForCausalLM
 
-tokenizer = LlamaTokenizer.from_pretrained("decapoda-research/llama-7b-hf")
+BASE_MODEL = None
+assert (
+    BASE_MODEL
+), "Please specify a BASE_MODEL in the script, e.g. 'decapoda-research/llama-7b-hf'"
+
+tokenizer = LlamaTokenizer.from_pretrained(BASE_MODEL)
 
 base_model = LlamaForCausalLM.from_pretrained(
-    "decapoda-research/llama-7b-hf",
+    BASE_MODEL,
     load_in_8bit=False,
     torch_dtype=torch.float16,
     device_map={"": "cpu"},

+ 7 - 2
export_state_dict_checkpoint.py

@@ -11,10 +11,15 @@ assert (
 ), "LLaMA is now in HuggingFace's main branch.\nPlease reinstall it: pip uninstall transformers && pip install git+https://github.com/huggingface/transformers.git"
 from transformers import LlamaTokenizer, LlamaForCausalLM
 
-tokenizer = LlamaTokenizer.from_pretrained("decapoda-research/llama-7b-hf")
+BASE_MODEL = None
+assert (
+    BASE_MODEL
+), "Please specify a BASE_MODEL in the script, e.g. 'decapoda-research/llama-7b-hf'"
+
+tokenizer = LlamaTokenizer.from_pretrained(BASE_MODEL)
 
 base_model = LlamaForCausalLM.from_pretrained(
-    "decapoda-research/llama-7b-hf",
+    BASE_MODEL,
     load_in_8bit=False,
     torch_dtype=torch.float16,
     device_map={"": "cpu"},

+ 6 - 4
finetune.py

@@ -36,6 +36,10 @@ TARGET_MODULES = [
 ]
 DATA_PATH = "alpaca_data_cleaned.json"
 OUTPUT_DIR = "lora-alpaca"
+BASE_MODEL = None
+assert (
+    BASE_MODEL
+), "Please specify a BASE_MODEL in the script, e.g. 'decapoda-research/llama-7b-hf'"
 
 device_map = "auto"
 world_size = int(os.environ.get("WORLD_SIZE", 1))
@@ -45,13 +49,11 @@ if ddp:
     GRADIENT_ACCUMULATION_STEPS = GRADIENT_ACCUMULATION_STEPS // world_size
 
 model = LlamaForCausalLM.from_pretrained(
-    "decapoda-research/llama-7b-hf",
+    BASE_MODEL,
     load_in_8bit=True,
     device_map=device_map,
 )
-tokenizer = LlamaTokenizer.from_pretrained(
-    "decapoda-research/llama-7b-hf", add_eos_token=True
-)
+tokenizer = LlamaTokenizer.from_pretrained(BASE_MODEL, add_eos_token=True)
 
 model = prepare_model_for_int8_training(model)
 

+ 7 - 3
generate.py

@@ -9,12 +9,16 @@ assert (
 ), "LLaMA is now in HuggingFace's main branch.\nPlease reinstall it: pip uninstall transformers && pip install git+https://github.com/huggingface/transformers.git"
 from transformers import LlamaTokenizer, LlamaForCausalLM, GenerationConfig
 
-tokenizer = LlamaTokenizer.from_pretrained("decapoda-research/llama-7b-hf")
-
 LOAD_8BIT = False
-BASE_MODEL = "decapoda-research/llama-7b-hf"
+BASE_MODEL = None
 LORA_WEIGHTS = "tloen/alpaca-lora-7b"
 
+tokenizer = LlamaTokenizer.from_pretrained(BASE_MODEL)
+
+assert (
+    BASE_MODEL
+), "Please specify a BASE_MODEL in the script, e.g. 'decapoda-research/llama-7b-hf'"
+
 if torch.cuda.is_available():
     device = "cuda"
 else: