当前位置:   article > 正文

[linux] huggingface transformers 如何下载模型至本地 & git lfs install 报错_git_lfs_skip_smudge=1

git_lfs_skip_smudge=1

bert-base-uncased at main

一、官方给出的命令:

  1. # Make sure you have git-lfs installed (https://git-lfs.com)
  2. git lfs install
  3. git clone https://huggingface.co/bert-base-uncased
  4. # if you want to clone without large files – just their pointers
  5. # prepend your git clone with the following env var:
  6. GIT_LFS_SKIP_SMUDGE=1

但是 git lfs install 的时候报错。

于是查了一下。。。。安装lfs是要这样: 

二、安装 lfs

You can't directly use

git lfs install

Instead of that, you can use these commands to download and install (you have to download it before installing).

  1. # for linux
  2. # 如果报错,则用 sudo apt-get update
  3. sudo apt-get install git-lfs
  4. git-lfs install
  5. # for mac
  6. brew install git-lfs
  7. #用git-lfs install检查是否正确安装
  8. git-lfs install

网络不好mac报错:重新安了一下brew install git-lfs。。

三、 再用官方的命令下载。

如果失败,则。。。可能是网络太差。。。。

最终,我还是给 from_pretrained 套了循环,来解决的。。。。。。。

如果不套循环,会报错 " requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))" 。。。。。。。。。。。。。。。。。。。。。

  1. class Trainer(object):
  2. def __init__(self, args, train_dataset=None, dev_dataset=None, test_dataset=None):
  3. self.args = args
  4. self.train_dataset = train_dataset
  5. self.dev_dataset = dev_dataset
  6. self.test_dataset = test_dataset
  7. self.intent_label_lst = get_intent_labels(args)
  8. self.slot_label_lst = get_slot_labels(args)
  9. # Use cross entropy ignore index as padding label id so that only real label ids contribute to the loss later
  10. self.pad_token_label_id = args.ignore_index
  11. self.config_class, self.model_class, _ = MODEL_CLASSES[args.model_type]
  12. #self.config = self.config_class.from_pretrained(args.model_name_or_path, finetuning_task=args.task, output_hidden_states=args.output_hidden_states)
  13. self.config = self.config_class.from_pretrained(args.model_name_or_path, finetuning_task=args.task)
  14. ################## [O.O]这是一个循环,解决下不下来模型的问题 #################
  15. nb_tries = 20
  16. while nb_tries>0:
  17. nb_tries -= 1
  18. try:
  19. self.model = self.model_class.from_pretrained(args.model_name_or_path,
  20. config=self.config,
  21. args=args,
  22. intent_label_lst=self.intent_label_lst,
  23. slot_label_lst=self.slot_label_lst)
  24. break
  25. except:
  26. time.sleep(0.1)
  27. #########################################################################
  28. # GPU or CPU
  29. self.device = "cuda" if torch.cuda.is_available() else "cpu"
  30. # self.device = "cuda" if torch.cuda.is_available() and not args.no_cuda else "cpu"
  31. self.model.to(self.device)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/453079
推荐阅读
相关标签
  

闽ICP备14008679号