Skip to content

Commit

Permalink
Fix bug in TF when used with Sphinx's doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
drasmuss authored and tbekolay committed May 28, 2021
1 parent 4801d90 commit af78d9a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions nengo_dl/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,29 @@ def sub_layers(layer):
"""Get layers contained in ``layer``."""
return layer._self_tracked_trackables

# monkeypatch to fix bug when using TF2.5 with sphinx's doctest extension
from tensorflow.python.autograph.impl.api import StackTraceMapper

old_source_map = StackTraceMapper.get_effective_source_map

def get_effective_source_map(self):
"""
Sometimes the source file is unknown (e.g. when running code through Sphinx's
doctest builder). This causes TensorFlow to crash (as of TF 2.5). So we convert
any Nones to the string "unknown".
"""

effective_source_map = old_source_map(self)

# convert Nones to "unknown"
effective_source_map = {
key: tuple("unknown" if x is None else x for x in val)
for key, val in effective_source_map.items()
}
return effective_source_map

StackTraceMapper.get_effective_source_map = get_effective_source_map


# Nengo compatibility

Expand Down

0 comments on commit af78d9a

Please sign in to comment.