This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 185
Expand file tree
/
Copy pathdebug_ops.py
More file actions
44 lines (36 loc) · 1.3 KB
/
debug_ops.py
File metadata and controls
44 lines (36 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
##############################################################
# Copyright (c) 2018-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
##############################################################
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import numpy as np
import pdb
import traceback as tb
import code
class PDBOp(object):
""" Simply for debugging. Do a pdb in the graph.
"""
def forward(self, input_tensor, output_tensor):
inputs = [el.data for el in input_tensor]
# some standard debugging stuff
print('>> Inputs have NaN?: {}'.format([
np.any(np.isnan(el)) for el in inputs]))
pdb.set_trace()
class TDBOp(object):
""" Better version of PDB
"""
def forward(self, input_tensor, output_tensor):
inputs = [el.data for el in input_tensor]
# some standard debugging stuff
print('>> Inputs have NaN?: {}'.format([
np.any(np.isnan(el)) for el in inputs]))
tb.print_stack()
namespace = globals().copy()
namespace.update(locals())
code.interact(local=namespace)