Lora fine-tuning taking too long

huangapple go评论127阅读模式
英文:

Lora fine-tuning taking too long

问题

以下是翻译好的部分:

  1. from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig, pipeline
  2. import transformers
  3. import torch
  4. model_id = "tiiuae/falcon-40b-instruct"
  5. bnb_config = BitsAndBytesConfig(
  6. load_in_4bit=True,
  7. bnb_4bit_use_double_quant=True,
  8. bnb_4bit_quant_type="nf4",
  9. bnb_4bit_compute_dtype=torch.bfloat16
  10. )
  11. tokenizer = AutoTokenizer.from_pretrained(model_id)
  12. tokenizer.pad_token = tokenizer.eos_token
  13. model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_config, device_map="auto", trust_remote_code=True)
  14. from peft import prepare_model_for_kbit_training
  15. model.gradient_checkpointing_enable()
  16. model = prepare_model_for_kbit_training(model)
  17. from peft import LoraConfig, get_peft_model
  18. config = LoraConfig(
  19. r=16,
  20. lora_alpha=32,
  21. target_modules=["query_key_value"],
  22. lora_dropout=0.05,
  23. bias="none",
  24. task_type="CAUSAL_LM"
  25. )
  26. model = get_peft_model(model, config)
  27. trainer = transformers.Trainer(
  28. model=model,
  29. train_dataset=tokenized_data,
  30. args=transformers.TrainingArguments(
  31. num_train_epochs=100,
  32. per_device_train_batch_size=4,
  33. gradient_accumulation_steps=4,
  34. warmup_ratio=0.05,
  35. learning_rate=2e-4,
  36. fp16=False,
  37. logging_steps=1,
  38. output_dir="output",
  39. optim="paged_adamw_8bit",
  40. lr_scheduler_type='cosine',
  41. ),
  42. data_collator=transformers.DataCollatorForLanguageModeling(tokenizer, mlm=False),
  43. )
  44. model.config.use_cache = False # silence the warnings. Please re-enable for inference!
  45. trainer.train()
英文:

Any reason why this is giving me a month of expected processing time?

More importantly, how to speed this up?

My dataset is a collection of 20k short sentences (max 100 words each).

  1. import transformers
  2. import torch
  3. model_id = "tiiuae/falcon-40b-instruct"
  4. bnb_config = BitsAndBytesConfig(
  5. load_in_4bit=True,
  6. bnb_4bit_use_double_quant=True,
  7. bnb_4bit_quant_type="nf4",
  8. bnb_4bit_compute_dtype=torch.bfloat16
  9. )
  10. tokenizer = AutoTokenizer.from_pretrained(model_id)
  11. tokenizer.pad_token = tokenizer.eos_token
  12. model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_config, device_map="auto", trust_remote_code=True)
  13. from peft import prepare_model_for_kbit_training
  14. model.gradient_checkpointing_enable()
  15. model = prepare_model_for_kbit_training(model)
  16. from peft import LoraConfig, get_peft_model
  17. config = LoraConfig(
  18. r=16,
  19. lora_alpha=32,
  20. target_modules=["query_key_value"],
  21. lora_dropout=0.05,
  22. bias="none",
  23. task_type="CAUSAL_LM"
  24. )
  25. model = get_peft_model(model, config)
  26. trainer = transformers.Trainer(
  27. model=model,
  28. train_dataset=tokenized_data,
  29. args=transformers.TrainingArguments(
  30. num_train_epochs=100,
  31. per_device_train_batch_size=4,
  32. gradient_accumulation_steps=4,
  33. warmup_ratio=0.05,
  34. learning_rate=2e-4,
  35. fp16=False,
  36. logging_steps=1,
  37. output_dir="output",
  38. optim="paged_adamw_8bit",
  39. lr_scheduler_type='cosine',
  40. ),
  41. data_collator=transformers.DataCollatorForLanguageModeling(tokenizer, mlm=False),
  42. )
  43. model.config.use_cache = False # silence the warnings. Please re-enable for inference!
  44. trainer.train()```
  45. </details>
  46. # 答案1
  47. **得分**: 1
  48. 我认为原因是因为 GPU 没有被使用,如果你有一个 GPU,你可以启用它,并使用它进行微调。
  49. <details>
  50. <summary>英文:</summary>
  51. I think the reason is because the gpu is not being used, if you have one you could enable it and do fine tuning with that.
  52. </details>

huangapple
  • 本文由 发表于 2023年7月20日 22:36:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76730985.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定