I had a codebase that runs fine in PyTorch 0.4 but whenever I try to run it using PyTorch 1.0+, it complains about the following import.
from torch.nn._functions.thnn import rnnFusedPointwise as fusedBackend
I use fusedBackend in the following code snippet.
if input.is_cuda:
igates = F.linear(input, w_ih)
hgates = F.linear(hx, w_hh)
state = fusedBackend.LSTMFused.apply
return state(igates, hgates, cx, b_ih, b_hh)
Is there any way I can fix the import error for PyTorch 1.0+?
Related
I'm playing around a code from a book, however, there is an error that I can't manage to solve. This is my code:
from tensorboard.plugins.hparams import api_pb2
from tensorboard.plugins.hparams import summary as hparams_summary
def run_experiment(run_dir, hparams):
writer = tf.summary.create_file_writer(run_dir)
summary_start = hparams_summary.session_start_pb(hparams=hparams)
with writer.as_default():
accuracy = train_test_hp(hparams)
summary_end = hparams_summary.session_end_pb(api_pb2.STATUS_SUCCESS)
tf.summary.scalar('accuracy',accuracy,step=1,description="The accuracy")
tf.summary.import_event(tf.compat.v1.Event(summary=summary_start).SerializeToString())
tf.summary.import_event(tf.compat.v1.Event(summary=summary_end).SerializeToString())
return accuracy
This is the error I got:
module 'tensorboard.summary._tf.summary' has no attribute
'import_event'
I'm using colab. Please give me ideas about resolving the error. Your help means a lot to me!
Changing lines:
tf.summary.import_event(tf.compat.v1.Event(summary=summary_start).SerializeToString())
tf.summary.import_event(tf.compat.v1.Event(summary=summary_end).SerializeToString())
to:
tf.compat.v1.summary.Event(summary=summary_start).SerializeToString()
tf.compat.v1.summary.Event(summary=summary_end).SerializeToString()
solves the problem.
I'm trying to run an animation using matplotlib FuncAnimation and I keep running into the error
"Requested MovieWriter (ffmpeg) not available". I realize this question has been asked before, and I have looked at every response to this and none have worked.
I'm running a jupyter notebook on Windows 10
I've got the following code.
from matplotlib.animation import FuncAnimation
def init():
ax.clear()
nice_axes(ax)
ax.set_ylim(.2, 6.8)
def update(i):
for bar in ax.containers:
bar.remove()
y = df_rank_expanded.iloc[i]
width = df_expanded.iloc[i]
ax.barh(y=y, width=width, color=colors, tick_label=labels)
date_str = df_expanded.index[i].strftime('%B %-d, %Y')
ax.set_title(f'Racial Unemployment - {date_str}', fontsize='smaller')
fig = plt.Figure(figsize=(4, 2.5), dpi=144)
ax = fig.add_subplot()
anim = FuncAnimation(fig=fig, func=update, init_func=init, frames=len(df_expanded),
interval=100, repeat=False)
When I run
from IPython.display import HTML
HTML(anim.to_html5_video())
I get the error RuntimeError: Requested MovieWriter (ffmpeg) not available
Here is what I've tried.
1) installing ffmpeg on my system, and setting the path value. I followed the instructions here https://www.wikihow.com/Install-FFmpeg-on-Windows
I verified FFmpeg was installed by typing ffmpeg -version in the cmd window
2) conda install -c conda-forge ffmpeg
This still results in the ffmpeg not available error.
3)I've followed instructions here
Matplotlib-Animation "No MovieWriters Available" which just say to do 1 and 2 above
4) Here Stop Matplotlib Jupyter notebooks from showing plot with animation
which suggests using
HTML(anim.to_jshtml())
However, this gives me an invalid format string error for date_str = df_expanded.index[i].strftime('%B %-d, %Y')
5) I've set the path variable directly in the jupyter notebook
plt.rcParams['animation.ffmpeg_path'] = 'C:\FFmpeg\ffmpeg-20200610-9dfb19b-win64-static\bin\ffmpeg.exe'
6) Restarting my kernel
7) Rebooting my system
8) Breaking my computer into small pieces, grinding those through an industrial shredder, burning the pieces, salting the earth where they lay, and then getting an entirely new computer and trying everything all over.
So far, nothing has worked. When I run sample code at http://louistiao.me/posts/notebooks/embedding-matplotlib-animations-in-jupyter-as-interactive-javascript-widgets/ I can get it to work, using their code only.
But I cannot get my own code to work. Any help would be much appreciated. Thanks!
plt.rcParams['animation.ffmpeg_path'] = 'C:\FFmpeg\ffmpeg-20200610-9dfb19b-win64-static\bin\ffmpeg.exe'
here you have to add r in front of 'C:~~~' as r'C:~~~'
plt.rcParams['animation.ffmpeg_path'] = r'C:\FFmpeg\ffmpeg-20200610-9dfb19b-win64-static\bin\ffmpeg.exe'
I don't know if you have tried this, but for me here it worked when I set a variable before calling HTML:
from IPython.display import HTML
html = anim.to_html5_video()
HTML(html)
Set up runtime: python3 and GPU.
Run the code step by step.
I only successfully run the code at first time.
After that, when run the below part, occured "RuntimeError: CUDA error: invalid device function"
sequence = np.array(tacotron2.text_to_sequence(text, ['english_cleaners']))[None, :]
sequence = torch.from_numpy(sequence).to(device='cuda', dtype=torch.int64)
with torch.no_grad():
_, mel, _, _ = tacotron2.infer(sequence)
audio = waveglow.infer(mel)
audio_numpy = audio[0].data.cpu().numpy()
rate = 22050
Do you know the root cause? And does the pre-trained model be run on local CPU?
At the time of writing, you can solve this issue by adding
!pip install torch==1.1.0 torchvision==0.3.0
before import torch
in https://colab.research.google.com/github/pytorch/pytorch.github.io/blob/master/assets/hub/nvidia_deeplearningexamples_tacotron2.ipynb
I am trying to use a QRNN based encoder for text classification by tuning a QRNN pretrained LM.
Here is the configuration of qrnn
emb_sz:int = 400
nh: int = 1550
nl: int = 3
qrnn_config = copy.deepcopy(awd_lstm_lm_config)
dps = dict(output_p=0.25, hidden_p=0.1, input_p=0.2, embed_p=0.02, weight_p=0.15)
qrnn_config.update({'emb_sz':emb_sz, 'n_hid':nh, 'n_layers':nl, 'pad_token':1, 'qrnn':True})
qrnn_config
I am passing configuration to lm_learner
lm_learner = language_model_learner(data_lm, AWD_LSTM, config=qrnn_config, pretrained=False,drop_mult=.1,pretrained_fnames=(pretrained_lm_fname,pretrained_itos_fname))
What I am getting is:
ImportError: No module named 'forget_mult_cuda'
Fast-ai version is: '1.0.51.dev0'
Try cleaning cuda cash using
gc.collect()
torch.cuda.empty_cache()
Use this for updating QRnn to true
language model
config = awd_lstm_lm_config.copy()
config['qrrn']=True
Classification model
config = awd_lstm_clas_config.copy()
config['qrrn']=True
config
You need not copy anything from source code.
It seems that you're missing ninja package.
Use:
pip install ninja
And restart your notebook, if you're using it.
from fipy import *
nx = 50
dx = 1.
mesh = Grid1D(nx=nx, dx=dx)
phi = CellVariable(name="solution variable",
mesh=mesh,
value=0.)
D = 1.
valueLeft = 1
valueRight = 0
phi.constrain(valueRight, mesh.facesRight)
phi.constrain(valueLeft, mesh.facesLeft)
eqX = TransientTerm() == ExplicitDiffusionTerm(coeff=D)
timeStepDuration = 0.9 * dx**2 / (2 * D)
steps = 100
phiAnalytical = CellVariable(name="analytical value",
mesh=mesh)
viewer = Viewer(vars=(phi, phiAnalytical),
datamin=0., datamax=1.)
viewer.plot()
x = mesh.cellCenters[0]
t = timeStepDuration * steps
try:
from scipy.special import erf
phiAnalytical.setValue(1 - erf(x / (2 * numerix.sqrt(D * t))))
except ImportError:
print "The SciPy library is not available to test the solution to \
the transient diffusion equation"
for step in range(steps):
eqX.solve(var=phi,
dt=timeStepDuration)
viewer.plot()
I am trying to implement an example from the fipy examples list which is the 1D diffusion problem. but I am not able to view the result as a plot.
I have defined viewer correctly as suggested in the code for the example. Still not helping.
The solution vector runs fine.
But I am not able to plot using the viewer function. can anyone help? thank you!
Your code works fine on my computer. Probably is a problem with a plotting library used by FiPy.
Check if the original example works (just run this from the fipy folder)
python examples/diffusion/mesh1D.py
If not, download FiPy from the github page of the project https://github.com/usnistgov/fipy and try the example again. If not, check if the plotting libraries are correctly installed.
Anyways, you should specify the platform you are using and the errors you are getting. The first time I had some problems with the plotting libraries too.