Issue
My goal is to run some python scripts with pdb
or ipdb
in JupyterLab to capture my debugging history.
I first inserted set_trace()
in my python script:
import torch
from IPython.core.debugger import set_trace
def train_batch(model_instance, inputs_source, labels_source, inputs_target, optimizer, args):
inputs = torch.cat((inputs_source, inputs_target), dim=0)
total_loss, train_stats = model_instance.get_loss(inputs, labels_source)
total_loss[args.train_loss].backward()
set_trace() # insert breakpoint
optimizer.step()
return train_stats
I then run this script in my JupyterLab:
!python ./trainer/train.py \
--base_config ./config/sgd_vannila_0.001.yml \
--dataset Office-Home \
--class_num 50 \
--src_address ./data/office-home/Art.txt \
--tgt_address ./data/office-home/Clipart.txt \
--name transfer.debug.rand_noise \
--train_steps 10000 \
--seed 2 \
--filter_classes=0,50 \
--eval_interval 50
The execution stops at the breakpoint, but does not provide an interactive box to prompt any ipdb
instructions. The same is happening for pdb
or jupyter notebook.
Things I have tried:
- restarting Chrome browser, or my laptop, does not help
- adding breakpoint inside the notebook code block works (please see screenshot below), but I would like to be able to debug code written in my python module file
Version information:
- ipdb-0.12.2
- Python 3.6.9
- JupyterLab 0.35.5
Solution
You can do it with the %run magic command.
%run ./trainer/train.py \
--base_config ./config/sgd_vannila_0.001.yml \
--dataset Office-Home \
--class_num 50 \
--src_address ./data/office-home/Art.txt \
--tgt_address ./data/office-home/Clipart.txt \
--name transfer.debug.rand_noise \
--train_steps 10000 \
--seed 2 \
--filter_classes=0,50 \
--eval_interval 50
Answered By - mooihi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.