How to fix 'ModuleNotFoundError: No module named transformer.modules' while profiling a Python script with cProfile?
Trying to profile a python script using cProfile. It has subfiles being called encoder.py and decoder.py in the directory "modules" in "transformer". When I profile it, error shows module error, trasformer is not a module. Though I am not understanding what is the exact issue here.
The header files are as below:
import cProfile
import pstats
import sys, os
from pathlib import Path
sys.path[0] = str(Path(sys.path[0]).parent)
import numpy as np
try:
import cupy as cp
is_cupy_available = True
print('CuPy is available. Using CuPy for all computations.')
except:
is_cupy_available = False
print('CuPy is not available. Switching to NumPy.')
import pickle as pkl
from tqdm import tqdm
from transformer.modules import Encoder
from transformer.modules import Decoder
from transformer.optimizers import Adam, Nadam, Momentum, RMSProp, SGD, Noam
from transformer.losses import CrossEntropy
from transformer.prepare_data import DataPreparator
import matplotlib.pyplot as plt
when I run the command on terminal:
python -m cProfile -o result.dat transformer.py
this error shows up: ModuleNotFoundError: No module named 'transformer.modules'; 'transformer' is not a package
File "D:\Thesis\numpy-transformer-master\transformer\.\transformer.py", line 28, in <module>
from transformer.modules import Encoder
ModuleNotFoundError: No module named 'transformer.modules'; 'transformer' is not a package
init.py is already a part of the directory module.
The overall structure of the file is attached as image.
How to resolve this issue The structure of th dirctory in the code is given below
The code structure of sub directories
**The code runs fine and produces desired results if I run without profile command
python transformer.py
source https://stackoverflow.com/questions/76381090/how-to-fix-modulenotfounderror-no-module-named-transformer-modules-while-prof
Comments
Post a Comment