Skip to content

Commit

Permalink
Allow defining layer types in a notebook
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 307496529
  • Loading branch information
trax-robot authored and Copybara-Service committed Apr 20, 2020
1 parent f3e11e5 commit 172819b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion trax/layers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,11 @@ def _find_frame(frame):
while frame.f_code.co_name in ['__init__', 'gin_wrapper', '_validate',
'_validate_forward_inputs', '_init']:
# We only skip __init__ in internal layers, return otherwise.
dirname = frame.f_code.co_filename.split('/')[-2]
try:
dirname = frame.f_code.co_filename.split('/')[-2]
except IndexError:
# Notebook cells have dummy filenames that do not contain any slashes
dirname = frame.f_code.co_filename
if dirname != 'layers' and frame.f_code.co_name == '__init__':
return frame
# If we are in an init, move up.
Expand Down

0 comments on commit 172819b

Please sign in to comment.