Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot import name '_accumulate' from 'torch._utils' #1243

Open
lIkesimba9 opened this issue Apr 24, 2024 · 2 comments
Open

cannot import name '_accumulate' from 'torch._utils' #1243

lIkesimba9 opened this issue Apr 24, 2024 · 2 comments

Comments

@lIkesimba9
Copy link

I want finetune model, and when i use trainer.ipynb i get this error `ImportError Traceback (most recent call last)
Cell In[1], line 4
2 import torch.backends.cudnn as cudnn
3 import yaml
----> 4 from train import train
5 from utils import AttrDict
6 import pandas as pd

File ~/pet/pcb/EasyOCR/trainer/train.py:15
12 import numpy as np
14 from utils import CTCLabelConverter, AttnLabelConverter, Averager
---> 15 from dataset import hierarchical_dataset, AlignCollate, Batch_Balanced_Dataset
16 from model import Model
17 from test import validation

File ~/pet/pcb/EasyOCR/trainer/dataset.py:13
11 import numpy as np
12 from torch.utils.data import Dataset, ConcatDataset, Subset
---> 13 from torch._utils import _accumulate
14 import torchvision.transforms as transforms
16 def contrast_grey(img):

ImportError: cannot import name '_accumulate' from 'torch._utils' (/home/simba9/anaconda3/envs/easyocr/lib/python3.9/site-packages/torch/_utils.py)`

@mdolensk
Copy link

Just ran into the same problem. Pytorch v2.3.0 no longer defines function _accumulate in torch/_utils.py. What worked for me was to patch the code from an older version, namely v2.2.0

def _accumulate(iterable, fn=lambda x, y: x + y):
    "Return running totals"
    # _accumulate([1,2,3,4,5]) --> 1 3 6 10 15
    # _accumulate([1,2,3,4,5], operator.mul) --> 1 2 6 24 120
    it = iter(iterable)
    try:
        total = next(it)
    except StopIteration:
        return
    yield total
    for element in it:
        total = fn(total, element)
        yield total

So, either find and downgrade to an older version of Pytorch such as v2.2.0 or use my workaround, which is:

  1. comment out the offending import statement in line 13
  2. append above code snippet to dataset.py

@samthakur587
Copy link

conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch

use this torch version with 11.3 toolkit and remove the troch and torchvision from requirements and then install the req.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants