<h3 dir="auto">What related GitHub issues or StackOverflow threads have you found by searching the web for your problem?</h3>
<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="213417771" data-permission-text="Title is private" data-url="https://github.com/tensorflow/tensorflow/issues/8284" data-hovercard-type="issue" data-hovercard-url="/tensorflow/tensorflow/issues/8284/hovercard" href="https://github.com/tensorflow/tensorflow/issues/8284">#8284</a><br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="187456302" data-permission-text="Title is private" data-url="https://github.com/tensorflow/tensorflow/issues/5406" data-hovercard-type="issue" data-hovercard-url="/tensorflow/tensorflow/issues/5406/hovercard" href="https://github.com/tensorflow/tensorflow/issues/5406">#5406</a></p>
<h3 dir="auto">Environment info</h3>
<p dir="auto">Operating System:</p>
<p dir="auto">macOS 10.12.3</p>
<p dir="auto">Installed version of CUDA and cuDNN:<br>
(please attach the output of <code class="notranslate">ls -l /path/to/cuda/lib/libcud*</code>):</p>
<p dir="auto">CPU only</p>
<ol dir="auto">
<li>The commit hash (<code class="notranslate">git rev-parse HEAD</code>) <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/tensorflow/tensorflow/commit/e895d5ca395c2362df4f5c8f08b68501b41f8a98/hovercard" href="https://github.com/tensorflow/tensorflow/commit/e895d5ca395c2362df4f5c8f08b68501b41f8a98"><tt>e895d5c</tt></a></li>
<li>The output of <code class="notranslate">bazel version</code></li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Build label: 0.4.4-homebrew
Build target: bazel-out/local-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Feb 2 01:05:15 2017 (1485997515)
Build timestamp: 1485997515
Build timestamp as int: 1485997515"><pre class="notranslate"><code class="notranslate">Build label: 0.4.4-homebrew
Build target: bazel-out/local-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Feb 2 01:05:15 2017 (1485997515)
Build timestamp: 1485997515
Build timestamp as int: 1485997515
</code></pre></div>
<h3 dir="auto">If possible, provide a minimal reproducible example (We usually don't have time to read hundreds of lines of your code)</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import tensorflow as tf
from tensorflow.python.framework.graph_util import convert_variables_to_constants

x = tf.placeholder(tf.float32, shape=(None), name=&quot;x&quot;)

def add_one(x):
  return tf.add(x, 1)

y = tf.map_fn(add_one, x)

y = tf.identity(y, name=&quot;y&quot;)

with tf.Session() as sess:
  print(tf.get_default_graph().as_graph_def().node)
  minimal_graph = convert_variables_to_constants(sess, sess.graph.as_graph_def(add_shapes=True), [&quot;y&quot;])
  tf.train.write_graph(minimal_graph, '.', 'minimal_graph.proto', as_text=False)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">tensorflow</span> <span class="pl-k">as</span> <span class="pl-s1">tf</span>
<span class="pl-k">from</span> <span class="pl-s1">tensorflow</span>.<span class="pl-s1">python</span>.<span class="pl-s1">framework</span>.<span class="pl-s1">graph_util</span> <span class="pl-k">import</span> <span class="pl-s1">convert_variables_to_constants</span>

<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">placeholder</span>(<span class="pl-s1">tf</span>.<span class="pl-s1">float32</span>, <span class="pl-s1">shape</span><span class="pl-c1">=</span>(<span class="pl-c1">None</span>), <span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">"x"</span>)

<span class="pl-k">def</span> <span class="pl-en">add_one</span>(<span class="pl-s1">x</span>):
  <span class="pl-k">return</span> <span class="pl-s1">tf</span>.<span class="pl-en">add</span>(<span class="pl-s1">x</span>, <span class="pl-c1">1</span>)

<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">map_fn</span>(<span class="pl-s1">add_one</span>, <span class="pl-s1">x</span>)

<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">identity</span>(<span class="pl-s1">y</span>, <span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">"y"</span>)

<span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-v">Session</span>() <span class="pl-k">as</span> <span class="pl-s1">sess</span>:
  <span class="pl-en">print</span>(<span class="pl-s1">tf</span>.<span class="pl-en">get_default_graph</span>().<span class="pl-en">as_graph_def</span>().<span class="pl-s1">node</span>)
  <span class="pl-s1">minimal_graph</span> <span class="pl-c1">=</span> <span class="pl-en">convert_variables_to_constants</span>(<span class="pl-s1">sess</span>, <span class="pl-s1">sess</span>.<span class="pl-s1">graph</span>.<span class="pl-en">as_graph_def</span>(<span class="pl-s1">add_shapes</span><span class="pl-c1">=</span><span class="pl-c1">True</span>), [<span class="pl-s">"y"</span>])
  <span class="pl-s1">tf</span>.<span class="pl-s1">train</span>.<span class="pl-en">write_graph</span>(<span class="pl-s1">minimal_graph</span>, <span class="pl-s">'.'</span>, <span class="pl-s">'minimal_graph.proto'</span>, <span class="pl-s1">as_text</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)</pre></div>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="package main

import (
  tf &quot;github.com/tensorflow/tensorflow/tensorflow/go&quot;
  &quot;io/ioutil&quot;
)

func main() {
  modelPath := &quot;cond_test/minimal_graph.proto&quot;
  graphDef, _ := ioutil.ReadFile(modelPath)
  graph := tf.NewGraph()
  graph.Import(graphDef, &quot;&quot;)
}"><pre class="notranslate"><span class="pl-k">package</span> main

<span class="pl-k">import</span> (
  tf <span class="pl-s">"github.com/tensorflow/tensorflow/tensorflow/go"</span>
  <span class="pl-s">"io/ioutil"</span>
)

<span class="pl-k">func</span> <span class="pl-en">main</span>() {
  <span class="pl-s1">modelPath</span> <span class="pl-c1">:=</span> <span class="pl-s">"cond_test/minimal_graph.proto"</span>
  <span class="pl-s1">graphDef</span>, <span class="pl-s1">_</span> <span class="pl-c1">:=</span> <span class="pl-s1">ioutil</span>.<span class="pl-en">ReadFile</span>(<span class="pl-s1">modelPath</span>)
  <span class="pl-s1">graph</span> <span class="pl-c1">:=</span> <span class="pl-s1">tf</span>.<span class="pl-en">NewGraph</span>()
  <span class="pl-s1">graph</span>.<span class="pl-en">Import</span>(<span class="pl-s1">graphDef</span>, <span class="pl-s">""</span>)
}</pre></div>
<h3 dir="auto">What other attempted solutions have you tried?</h3>
<ul dir="auto">
<li>Loading the graph without the <code class="notranslate">map_fn</code> works as expected. (<code class="notranslate">y = add_one(x)</code>)</li>
<li>Originally encountered problem using prebuild tensorflow for python: <code class="notranslate">pip install tensorflow</code></li>
<li>Same issue when saving / restoring using SavedModel routines.</li>
</ul>
<h3 dir="auto">Logs or other output that would be helpful</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5de318c]

runtime stack:
runtime.throw(0x40cdc29, 0x2a)
	/usr/local/go/src/runtime/panic.go:596 +0x95
runtime.sigpanic()
	/usr/local/go/src/runtime/signal_unix.go:274 +0x2db

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x40973d0, 0xc42004de60, 0x40b34e0)
	/usr/local/go/src/runtime/cgocall.go:131 +0xe2 fp=0xc42004de30 sp=0xc42004ddf0
github.com/tensorflow/tensorflow/tensorflow/go._Cfunc_TF_GraphImportGraphDef(0xbf00020, 0xd0be3f0, 0xd0bee20, 0xd0bd5a0)
	github.com/tensorflow/tensorflow/tensorflow/go/_obj/_cgo_gotypes.go:386 +0x45 fp=0xc42004de60 sp=0xc42004de30
github.com/tensorflow/tensorflow/tensorflow/go.(*Graph).Import.func7(0xbf00020, 0xd0be3f0, 0xd0bee20, 0xd0bd5a0)
	/Users/olav/go/src/github.com/tensorflow/tensorflow/tensorflow/go/graph.go:96 +0x121 fp=0xc42004de98 sp=0xc42004de60
github.com/tensorflow/tensorflow/tensorflow/go.(*Graph).Import(0xc42000e038, 0xc42008a000, 0x1ae9, 0x1ce9, 0x0, 0x0, 0x0, 0x0)
	/Users/olav/go/src/github.com/tensorflow/tensorflow/tensorflow/go/graph.go:96 +0x1ef fp=0xc42004df00 sp=0xc42004de98
main.main()
	/Users/olav/go/src/github.com/olavhn/infer/test.go:14 +0x112 fp=0xc42004df88 sp=0xc42004df00
runtime.main()
	/usr/local/go/src/runtime/proc.go:185 +0x20a fp=0xc42004dfe0 sp=0xc42004df88
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc42004dfe8 sp=0xc42004dfe0

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:2197 +0x1"><pre class="notranslate"><code class="notranslate">fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5de318c]

runtime stack:
runtime.throw(0x40cdc29, 0x2a)
	/usr/local/go/src/runtime/panic.go:596 +0x95
runtime.sigpanic()
	/usr/local/go/src/runtime/signal_unix.go:274 +0x2db

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x40973d0, 0xc42004de60, 0x40b34e0)
	/usr/local/go/src/runtime/cgocall.go:131 +0xe2 fp=0xc42004de30 sp=0xc42004ddf0
github.com/tensorflow/tensorflow/tensorflow/go._Cfunc_TF_GraphImportGraphDef(0xbf00020, 0xd0be3f0, 0xd0bee20, 0xd0bd5a0)
	github.com/tensorflow/tensorflow/tensorflow/go/_obj/_cgo_gotypes.go:386 +0x45 fp=0xc42004de60 sp=0xc42004de30
github.com/tensorflow/tensorflow/tensorflow/go.(*Graph).Import.func7(0xbf00020, 0xd0be3f0, 0xd0bee20, 0xd0bd5a0)
	/Users/olav/go/src/github.com/tensorflow/tensorflow/tensorflow/go/graph.go:96 +0x121 fp=0xc42004de98 sp=0xc42004de60
github.com/tensorflow/tensorflow/tensorflow/go.(*Graph).Import(0xc42000e038, 0xc42008a000, 0x1ae9, 0x1ce9, 0x0, 0x0, 0x0, 0x0)
	/Users/olav/go/src/github.com/tensorflow/tensorflow/tensorflow/go/graph.go:96 +0x1ef fp=0xc42004df00 sp=0xc42004de98
main.main()
	/Users/olav/go/src/github.com/olavhn/infer/test.go:14 +0x112 fp=0xc42004df88 sp=0xc42004df00
runtime.main()
	/usr/local/go/src/runtime/proc.go:185 +0x20a fp=0xc42004dfe0 sp=0xc42004df88
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc42004dfe8 sp=0xc42004dfe0

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:2197 +0x1
</code></pre></div>
<p dir="auto">Right now, to specify a particular GPU, I do something like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="gpu = 0
available_devices = os.environ['CUDA_VISIBLE_DEVICES'].split(',')
os.environ['CUDA_VISIBLE_DEVICES'] = available_devices[gpu]"><pre class="notranslate"><code class="notranslate">gpu = 0
available_devices = os.environ['CUDA_VISIBLE_DEVICES'].split(',')
os.environ['CUDA_VISIBLE_DEVICES'] = available_devices[gpu]
</code></pre></div>
<p dir="auto">after which TensorFlow will only allocate resources on the first GPU device. It would be nice to include a native way to do this.</p>
<p dir="auto">Side note: There isn't much documentation (any?) on <code class="notranslate">device_count</code>, so I'm not sure if it's meant to handle this. Either way, I have experimented with the <code class="notranslate">device_count</code>, but with no luck: if I use <code class="notranslate">device_count = {'GPU': 1}</code>, TensorFlow still allocates memory on all available GPUs.</p>