autodl常用工具&命令

以下内容仅为当前认识,可能有不足之处,欢迎讨论!



tar/zip命令

参考链接

文件目录打包👉tar -cf <zip_name>.tar <directory_name/file_name>

如果目录名或者文件名有多个,用空格分开就行。

文件目录解压缩👉tar xvf <zip_name>.tar

zip压缩当前目录下所有文件和文件夹压缩成zip文件。zip -r <file_name>.zip ./*

zip解压缩当前文件,unzip -o -d /directory <file_name>.zip,-o:不提示情况下覆盖文件,-d指明将文件加压缩到该目录下。

镜像版本参考

参考链接

常用镜像源

新版的Ubuntu要求使用https源

Conda源

anaconda的国内镜像源,主要用来加快使用conda下载安装python环境的速度

清华镜像:

https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main

https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64

https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64

北京外国语大学镜像:

https://mirrors.bfsu.edu.cn/anaconda/pkgs/main

https://mirrors.bfsu.edu.cn/anaconda/pkgs/free

https://mirrors.bfsu.edu.cn/anaconda/pkgs/main/linux-64

https://mirrors.bfsu.edu.cn/anaconda/pkgs/main/win-64

阿里云镜像:

https://mirrors.aliyun.com/anaconda/pkgs/main

https://mirrors.aliyun.com/anaconda/pkgs/free

https://mirrors.aliyun.com/anaconda/pkgs/main/linux-64

https://mirrors.aliyun.com/anaconda/pkgs/main/win-64

Pypi源

Pypi的国内镜像源,主要用来加快pip下载安装第三方库的速度

清华镜像:https://pypi.tuna.tsinghua.edu.cn/simple

中科大镜像:https://pypi.mirrors.ustc.edu.cn/simple/

阿里云镜像:https://mirrors.aliyun.com/pypi/simple

华中理工大学镜像:https://pypi.hustunique.com/

山东理工大学镜像:https://pypi.sdutlinux.org/

豆瓣镜像:https://pypi.douban.com/simple/

torch包全版本下载

https://download.pytorch.org/whl/torch_stable.html

torch和cuda版本对应

  • Torch 1.7.0 对应 CUDA 11.0
  • Torch 1.6.0 对应 CUDA 10.2
  • Torch 1.5.0 对应 CUDA 10.1
  • Torch 1.4.0 对应 CUDA 10.0
  • Torch 1.3.0 对应 CUDA 9.2
  • Torch 1.2.0 对应 CUDA 9.0
  • Torch 1.1.0 对应 CUDA 9.0
  • Torch 1.0.0 对应 CUDA 8.0

conda命令

conda环境的诸多命令,我常用的。

conda打包

conda打包当前环境命令/pip,conda list -e > requirements.txt 或者pip导出pip freeze > requirements.txt

conda批量安装环境包/pip,conda install --yes --file requirements.txt或者pip安装pip install -r requiremments.txt

conda 环境重命名

可以先复制一个新的,然后删除旧的;也可以直接更改名字。

conda环境复制和转移

参考链接

conda create --name <new_env_name> --clone <now_env_name>

新电脑与当前电脑有相同的平台和操作系统

①保存当前环境信息到txt文件中,然后联网安装。

conda list --explict requirements.txt
conda create --name <new_env> --file requirements.txt

②利用打包命令直接打包,打包的是文件,复制到其他电脑后解压使用。

#安装conda-pack包
conda install -c conda-forge conda-pack / pip install conda-pack

#打包环境,生成压缩文件my_env.tar.gz压缩文件
conda pack -n <my_env>

#解压缩文件

解压缩文件到新的电脑上,解压到对应env目录下,先在env目录中用打包环境的名字创建一个文件夹如mkdir my_env,然后将压缩包解压到这个目录tar -xzvf my_env -C /anaconda3/envs/my_env

查看环境是否存在conda info -e

conda环境删除

conda remove -n <env_name> --all

autodl显示Http Error

遇到问题:csdn transformers/trainer.py", line 3968, in create_accelerator_and_postprocess self.accelerator = Accelerator( NameError: name ‘Accelerator’ is not defined

用这个GitHub参考算是解决了,因为

在autoDL中打开conda配置vim ~/.condarc,使得能够更改源。更改源之后,终于能够正常下载了。

遇到问题:

RuntimeError: CUDA error: device-side assert triggered

CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.

For debugging consider passing CUDA_LAUNCH_BLOCKING=1.

main()
File “train.py”, line 744, in main
train_result = trainer.train(model_path=model_path)
File “/root/autodl-tmp/aliyun-race/simcse/trainers.py”, line 616, in train
self._maybe_log_save_evaluate(tr_loss, model, trial, epoch , ignore_keys_for_eval=“None”)
File “/root/miniconda3/envs/aliyun/lib/python3.7/site-packages/transformers/trainer.py”, line 2321, in _maybe_log_save_evaluate
metrics = self.evaluate(ignore_keys=ignore_keys_for_eval)
File “/root/autodl-tmp/aliyun-race/simcse/trainers.py”, line 141, in evaluate
results = se.eval(tasks)
File “/root/autodl-tmp/aliyun-race/SentEval/senteval/engine.py”, line 59, in eval
self.results = {x: self.eval(x) for x in name}
File “/root/autodl-tmp/aliyun-race/SentEval/senteval/engine.py”, line 59, in
self.results = {x: self.eval(x) for x in name}
File “/root/autodl-tmp/aliyun-race/SentEval/senteval/engine.py”, line 127, in eval
self.results = self.evaluation.run(self.params, self.batcher) ##跳转到了sts.py文件中,计算去了
File “/root/autodl-tmp/aliyun-race/SentEval/senteval/sts.py”, line 86, in run
enc1 = batcher(params, batch1) ##跳转到trainer中的batcher数据,准备编码 ,最后得到128*768, batch1是一个batch—_size的所有句子列表分元素
File “/root/autodl-tmp/aliyun-race/simcse/trainers.py”, line 124, in batcher
return pooler_output.cpu()

File “train.py”, line 781, in
main()
File “train.py”, line 744, in main
train_result = trainer.train(model_path=model_path)
File “/root/autodl-tmp/aliyun-race/simcse/trainers.py”, line 616, in train
#self._maybe_log_save_evaluate(tr_loss, model, trial, epoch , ignore_keys_for_eval=“None”)## 2024年3月24日
File “/root/miniconda3/envs/aliyun/lib/python3.7/site-packages/transformers/trainer.py”, line 2321, in _maybe_log_save_evaluate
metrics = self.evaluate(ignore_keys=ignore_keys_for_eval)
File “/root/autodl-tmp/aliyun-race/simcse/trainers.py”, line 141, in evaluate
results = se.eval(tasks)
File “/root/autodl-tmp/aliyun-race/SentEval/senteval/engine.py”, line 59, in eval
self.results = {x: self.eval(x) for x in name}
File “/root/autodl-tmp/aliyun-race/SentEval/senteval/engine.py”, line 59, in
self.results = {x: self.eval(x) for x in name}
File “/root/autodl-tmp/aliyun-race/SentEval/senteval/engine.py”, line 127, in eval
self.results = self.evaluation.run(self.params, self.batcher) ##跳转到了sts.py文件中,计算去了
File “/root/autodl-tmp/aliyun-race/SentEval/senteval/sts.py”, line 86, in run
enc1 = batcher(params, batch1) ##跳转到trainer中的batcher数据,准备编码 ,最后得到128*768, batch1是一个batch—_size的所有句子列表分元素
File “/root/autodl-tmp/aliyun-race/simcse/trainers.py”, line 124, in batcher
return pooler_output.cpu()
RuntimeError: CUDA error: device-side assert triggered
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.

出现该问题,说明下载链接有问题,或者网不行,执行命令或者更换源就行。参考CSDN,以及额外的参考参考2

Conda hangs after Solving environment HTTP Error 429

执行命令:conda config --set ssl_verify no/false

或者进入配置文件中更换源

(base) $ cat .condarc
channels:
  - conda-forge
#  - defaults
channel_priority: strict
ssl_verify: false
(base) $ vim .condarc

添加镜像网站,删除原来的镜像网站。以及更改为http

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/

SentEval安装&模型路径问题

问题:

File "train.py", line 776, in <module>
    main()
  File "train.py", line 515, in main
    config = AutoConfig.from_pretrained(model_args.config_name, **config_kwargs)
  File "/root/miniconda3/envs/cluster/lib/python3.7/site-packages/transformers/models/auto/configuration_auto.py", line 360, in from_pretrained
    config_dict, _ = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
  File "/root/miniconda3/envs/cluster/lib/python3.7/site-packages/transformers/configuration_utils.py", line 420, in get_config_dict
    use_auth_token=use_auth_token,
  File "/root/miniconda3/envs/cluster/lib/python3.7/site-packages/transformers/file_utils.py", line 1056, in cached_path
    local_files_only=local_files_only,
  File "/root/miniconda3/envs/cluster/lib/python3.7/site-packages/transformers/file_utils.py", line 1235, in get_from_cache
    "Connection error, and we cannot find the requested files in the cached path."
ValueError: Connection error, and we cannot find the requested files in the cached path. Please try again or make sure your Internet connection is on.

出现这个问题,是找不到我的模型路径导致的。

那这个模型路径写成了什么?

尝试:/root/autodl-tmp/autodl-clusterNS/bert-base-uncased失败,换成./root失败,换成root失败。

想起来这个里面是空的,为什么是空的?

以及使用senteval包,需要额外的方式。不能使用pip install senteval,需要到SentEval文件夹中,用该命令python setup.py install才能安装好这个包。参考CSDN

修改代码:

data_dir:Optional[str]=field(
    default="data",
    metadata = {"help":"the data dir"}
)
    
cache_dir: Optional[str] = field(
    default="cache_dir",####希望将huggingface.co下载的预训练模型存储到哪里?
    metadata={"help": "Where do you want to store the pretrained models downloaded from huggingface.co"},
)

BATCH_SIZE = 512
BERT = 'bert-base-uncased'
#修改

同时将simcse中的init文件写入:

from .tool import SimCSE
from .trainers import CLTrainer,PATH_TO_SENTEVAL,PATH_TO_DATA
from .models import MLPLayer,Similarity,Pooler,cl_init,cl_forward,sentemb_forward,BertForCL,RobertaForCL,kmeans_cluster

比如打印路径。
2024年3月26日09点49分,经过init文件导入可以了。


显存占用

后来遇到显存占用的问题,也就是out of memory。用官方给出的解决办法,直接把所有的进程给删了。

ps -ef | grep train | awk '{print $2}' | xargs kill -9

或者使用代码清理下内存

import torch
torch.cuda.empty_cache()

以上是我的学习笔记,希望对你有所帮助!
如有不当之处欢迎指出!谢谢!

学吧,学无止境,太深了

  • 28
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HelpFireCode

随缘惜缘不攀缘。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值