【问题标题】:Trouble with OpenNMT Toy Example (Python3.9)OpenNMT 玩具示例的问题(Python3.9)
【发布时间】:2023-04-09 11:37:02
【问题描述】:

我最近安装了 OpenNMT,但在浏览玩具示例时出现以下错误。

我有 macOS Big Sur 11.2.1 我已经安装了 python2.7 和 python3.9。

pip install --upgrade OpenNMT-py==2.0.0rc1

wget https://s3.amazonaws.com/opennmt-trainingdata/toy-ende.tar.gz

tar xf toy-ende.tar.gz

cd toy_ende

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/bin/onmt_build_vocab", line 8, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/onmt/bin/build_vocab.py", line 63, in main
    build_vocab_main(opts)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/onmt/bin/build_vocab.py", line 23, in build_vocab_main
    ArgumentParser.validate_prepare_opts(opts, build_vocab_only=True)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/onmt/utils/parse.py", line 127, in validate_prepare_opts
    cls._validate_data(opt)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/onmt/utils/parse.py", line 42, in _validate_data
    cls._validate_file(path_src, info=f'{cname}/path_src')
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/onmt/utils/parse.py", line 18, in _validate_file
    raise IOError(f"Please check path of your {info} file!")
OSError: Please check path of your corpus_1/path_src file!

【问题讨论】:

  • 目录是toy-ende,而不是toy_ende

标签: python-3.x opennmt


【解决方案1】:

您可以按照以下步骤操作:

pip install --upgrade OpenNMT-py==2.0.0rc1;
wget https://s3.amazonaws.com/opennmt-trainingdata/toy-ende.tar.gz;
tar xf toy-ende.tar.gz;
echo '## Where the samples will be written
save_data: toy-ende/run/example
## Where the vocab(s) will be written
src_vocab: toy-ende/run/example.vocab.src
tgt_vocab: toy-ende/run/example.vocab.tgt
# Prevent overwriting existing files in the folder
overwrite: False

# Corpus opts:
data:
    corpus_1:
        path_src: toy-ende/src-train.txt
        path_tgt: toy-ende/tgt-train.txt
    valid:
        path_src: toy-ende/src-val.txt
        path_tgt: toy-ende/tgt-val.txt
' > toy_en_de.yaml;
mkdir toy-ende/run;
touch toy-ende/run/example.vocab.src;
touch toy-ende/run/example.vocab.tgt;
onmt_build_vocab -config toy_en_de.yaml -n_sample 10000;

echo '# Vocabulary files that were just created
src_vocab: toy-ende/run/example.vocab.src
tgt_vocab: toy-ende/run/example.vocab.tgt

# Train on a single GPU
world_size: 1
gpu_ranks: [0]

# Where to save the checkpoints
save_model: toy-ende/run/model
save_checkpoint_steps: 500
train_steps: 1000
valid_steps: 500
' >> toy_en_de.yaml;
onmt_train -config toy_en_de.yaml;

如果您没有 GPU,则需要删除或注释以下行:

# Train on a single GPU
world_size: 1
gpu_ranks: [0]

【讨论】:

  • 那么我应该在 toy-ende 文件夹之外运行 omnt_build 和 onmt_train 命令吗?
  • 如果我在尝试运行训练命令后收到 AttributeError: module 'torch._C' has no attribute '_cuda_setDevice' 错误会怎样?谢谢
  • @JoseChavez 从toy-ende 文件夹的父文件夹运行这些命令,它应该可以工作。由于您似乎没有板载 GPU,因此您只能在 CPU 上运行,为此,您需要在 *.yml 文件中注释掉 world_size: 1gpu_ranks: [0] 行,请参阅 here
  • 谢谢。你知道我如何在 google colab GPU 上运行它吗?谢谢
  • 完成!感谢您的帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-08
  • 1970-01-01
  • 2020-09-15
  • 1970-01-01
  • 2018-12-11
  • 1970-01-01
  • 2021-10-10
相关资源
最近更新 更多