我已经使用conda安装了pytorch版本1.10.0和torchtext、torchvision和torchaudio。我的PyTorch是纯cpu的,我已经试验了conda install pytorch-mutex -c pytorch和conda install pytorch cpuonly -c pytorch来安装cpuonly版本,这两个版本都产生了我将在下面几行中描述的相同的错误。
我还在conda中安装了pytorch-lightning,并在环境中通过pip安装了jsonargparse[summaries。
我编写了这段代码来查看LightningCLI是否工作。
# script.py
import torch
import pytorch_lightning as pl
class BoringModel(LightningModule):
def __init__(self):
super().__init__()
self.layer = torch.nn.Linear(32, 2)
def forward(self, x):
return self.layer(x)
def training_step(self, batch, batch_idx):
loss = self(batch).sum()
self.log("train_loss", loss)
return {"loss": loss}
def validation_step(self, batch, batch_idx):
loss = self(batch).sum()
self.log("valid_loss", loss)
def test_step(self, batch, batch_idx):
loss = self(batch).sum()
self.log("test_loss", loss)
def configure_optimizers(self):
return torch.optim.SGD(self.layer.parameters(), lr=0.1)
cli = LightningCLI(BoringModel)但是,当我使用python -m script fit --print_config运行它时,我会得到以下错误:
ImportError: /home/farhood/miniconda3/envs/pytorch_dummy_environment/lib/python3.9/site-packages/torchtext/_torchtext.so: undefined symbol: _ZNK5torch3jit6MethodclESt6vectorIN3c106IValueESaIS4_EERKSt13unordered_mapISsS4_St4hashISsESt8equal_toISsESaISt4pairIKSsS4_EEE这表明我的Conda安装有问题,可能与torchtext有关。
以下是已安装的火炬相关软件包的版本:
pytorch 1.10.0 cpu_py39hc5866cc_0 conda-forge
pytorch-lightning 1.5.2 pyhd8ed1ab_0 conda-forge
pytorch-mutex 1.0 cuda pytorch
torchaudio 0.10.0 py39_cpu pytorch
torchmetrics 0.6.0 pyhd8ed1ab_0 conda-forge
torchtext 0.11.0 py39 pytorch
torchvision 0.11.1 py39_cpu pytorch发布于 2021-11-24 22:00:48
因此,为了解决这个问题,我不得不更改我的environment.yaml,以便迫使pytorch从pytorch通道安装。
现在这是我的environment.yaml:
channels:
- defaults
- pytorch
- conda-forge
dependencies:
# ML section
- pytorch::pytorch
- pytorch::torchtext
- pytorch::torchvision
- pytorch::torchaudio
- pytorch::cpuonly
- mlflow=1.21.0
- pytorch-lightning>=1.5.2
- pip:
- jsonargparse[signatures]用这个我就不会再犯错误了。现在安装的与火把有关的东西是:
cpuonly 2.0 0 pytorch
pytorch 1.10.0 py3.9_cpu_0 pytorch
pytorch-lightning 1.5.2 pyhd8ed1ab_0 conda-forge
pytorch-mutex 1.0 cpu pytorch
torchaudio 0.10.0 py39_cpu [cpuonly] pytorch
torchtext 0.11.0 py39 pytorch
torchvision 0.11.1 py39_cpu [cpuonly] pytorchhttps://stackoverflow.com/questions/70098916
复制相似问题