I'm having trouble with running the Bayesian Linear Regression example as below on my GPUs. Two NVidia GeForce 1080Ti are available.
Contained installation in tensorflow docker (tensorflow:1.14.0-gpu-py3-jupyter). Then installed inferpy by
pip install inferpy[all]
Then I had to downgrade the tensorflow-probability package from 0.8.0 to 0.7.0 (known bug). First, the script showed no GPUs available. Then I did:
pip uninstall tensorflow pip install tensorflow-gpu
The GPUs are now visible as shown by the prints, but inferpy still gives the same error.
`
import inferpy as inf
import tensorflow as tf
import numpy as np
@inf.probmodel
def linear_reg(d):
w0 = inf.Normal(0, 1, name="w0")
w = inf.Normal(np.zeros([d, 1]), 1, name="w")
with inf.datamodel():
x = inf.Normal(tf.ones(d), 2, name="x")
y = inf.Normal(w0 + x @ w, 1.0, name="y")
@inf.probmodel
def qmodel(d):
qw0_loc = inf.Parameter(0., name="qw0_loc")
qw0_scale = tf.math.softplus(inf.Parameter(1., name="qw0_scale"))
qw0 = inf.Normal(qw0_loc, qw0_scale, name="w0")
qw_loc = inf.Parameter(np.zeros([d, 1]), name="qw_loc")
qw_scale = tf.math.softplus(inf.Parameter(tf.ones([d, 1]), name="qw_scale"))
qw = inf.Normal(qw_loc, qw_scale, name="w")
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
print("GPU(s) available", tf.test.is_gpu_available())
with tf.device('/device:GPU:1'):
# create an instance of the model
m = linear_reg(d=2)
q = qmodel(2)
# create toy data
N = 1000
data = m.prior(["x", "y"], data={"w0": 0, "w": [[2], [1]]}, size_datamodel=N).sample()
x_train = data["x"]
y_train = data["y"]
# set and run the inference
VI = inf.inference.VI(qmodel(2), epochs=10000)
m.fit({"x": x_train, "y": y_train}, VI)
# extract the parameters of the posterior
m.posterior(["w", "w0"]).parameters()
`
Num GPUs Available: 2
WARNING: Logging before flag parsing goes to stderr.
W1008 15:36:36.023126 139756946933568 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/inferpy/models/prob_model.py:63: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.
W1008 15:36:36.042158 139756946933568 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/inferpy/models/random_variable.py:425: The name tf.variables_initializer is deprecated. Please use tf.compat.v1.variables_initializer instead.
GPU(s) available True
W1008 15:36:36.610001 139756946933568 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/inferpy/util/tf_graph.py:63: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.
W1008 15:36:36.731642 139756946933568 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/inferpy/models/prob_model.py:136: The name tf.global_variables is deprecated. Please use tf.compat.v1.global_variables instead.
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1355 try:
-> 1356 return fn(*args)
1357 except errors.OpError as e:
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)
1338 # Ensure any changes to the graph are reflected in the runtime.
-> 1339 self._extend_graph()
1340 return self._call_tf_sessionrun(
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in _extend_graph(self)
1373 with self._graph._session_run_lock(): # pylint: disable=protected-access
-> 1374 tf_session.ExtendSession(self._session)
1375
InvalidArgumentError: Cannot assign a device for operation inferpy-predict-enabled-w0: Could not satisfy explicit device specification '/device:GPU:1' because no supported kernel for GPU devices is available.
Colocation Debug Info:
Colocation group had the following types and supported devices:
Root Member(assigned_device_name_index_=-1 requested_device_name_='/device:GPU:1' assigned_device_name_='' resource_device_name_='/device:GPU:1' supported_device_types_=[CPU] possible_devices_=[]
Assign: GPU CPU
Identity: GPU CPU XLA_CPU XLA_GPU
VariableV2: CPU
Colocation members, user-requested devices, and framework assigned devices, if any:
inferpy-predict-enabled-w0 (VariableV2) /device:GPU:1
inferpy-predict-enabled-w0/Assign (Assign) /device:GPU:1
inferpy-predict-enabled-w0/read (Identity) /device:GPU:1
Op: VariableV2
Node attrs: shape=[], shared_name="", dtype=DT_BOOL, container=""
Registered kernels:
device='GPU'; dtype in [DT_INT64]
device='GPU'; dtype in [DT_DOUBLE]
device='GPU'; dtype in [DT_FLOAT]
device='GPU'; dtype in [DT_HALF]
device='CPU'
[[{{node inferpy-predict-enabled-w0}}]]
During handling of the above exception, another exception occurred:
InvalidArgumentError Traceback (most recent call last)
<ipython-input-1-f66d6dab9fcd> in <module>
28 with tf.device('/device:GPU:1'):
29 # create an instance of the model
---> 30 m = linear_reg(d=2)
31 q = qmodel(2)
32 # create toy data
/usr/local/lib/python3.6/dist-packages/inferpy/models/prob_model.py in wrapper(*args, **kwargs)
42 return builder(*args, **kwargs)
43 return ProbModel(
---> 44 builder=fn
45 )
46 return wrapper
/usr/local/lib/python3.6/dist-packages/inferpy/models/prob_model.py in __init__(self, builder)
70
71 # Now initialize vars and params for the model (no sample_shape)
---> 72 self.vars, self.params = self._build_model()
73
74 # This attribute contains the inference method used. If it is None, the `fit` function has not been used yet
/usr/local/lib/python3.6/dist-packages/inferpy/models/prob_model.py in _build_model(self)
139 # use edward2 model tape to capture RandomVariable declarations
140 with ed.tape() as model_tape:
--> 141 self.builder()
142
143 # get variables from parameters
/usr/local/lib/python3.6/dist-packages/inferpy/util/runtime.py in wrapper(*args, **kwargs)
84 with runner_scope():
85 # now execute the function and return the result
---> 86 return f(*args, **kwargs)
87
88 return wrapper
/usr/local/lib/python3.6/dist-packages/inferpy/models/prob_model.py in fn()
40 @util.tf_run_ignored
41 def fn():
---> 42 return builder(*args, **kwargs)
43 return ProbModel(
44 builder=fn
<ipython-input-1-f66d6dab9fcd> in linear_reg(d)
5 @inf.probmodel
6 def linear_reg(d):
----> 7 w0 = inf.Normal(0, 1, name="w0")
8 w = inf.Normal(np.zeros([d, 1]), 1, name="w")
9
/usr/local/lib/python3.6/dist-packages/inferpy/models/random_variable.py in func(*args, **kwargs)
373
374 # build the respective boolean and tf.Variables
--> 375 is_observed, observed_value = _make_predictable_variables(initial_value, rv_name)
376
377 # use this context to intercept the value using the tf.cond dependent on the previous tf.Variables
/usr/local/lib/python3.6/dist-packages/inferpy/models/random_variable.py in _make_predictable_variables(initial_value, rv_name)
423 name="inferpy-predict-{name}".format(name=rv_name or "default"))
424
--> 425 util.session.get_session().run(tf.variables_initializer([is_observed, observed_value]))
426
427 return is_observed, observed_value
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
948 try:
949 result = self._run(None, fetches, feed_dict, options_ptr,
--> 950 run_metadata_ptr)
951 if run_metadata:
952 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
1171 if final_fetches or final_targets or (handle and feed_dict_tensor):
1172 results = self._do_run(handle, final_targets, final_fetches,
-> 1173 feed_dict_tensor, options, run_metadata)
1174 else:
1175 results = []
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
1348 if handle is None:
1349 return self._do_call(_run_fn, feeds, fetches, targets, options,
-> 1350 run_metadata)
1351 else:
1352 return self._do_call(_prun_fn, handle, feeds, fetches)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1368 pass
1369 message = error_interpolation.interpolate(message, self._graph)
-> 1370 raise type(e)(node_def, op, message)
1371
1372 def _extend_graph(self):
InvalidArgumentError: Cannot assign a device for operation inferpy-predict-enabled-w0: Could not satisfy explicit device specification '/device:GPU:1' because no supported kernel for GPU devices is available.
Colocation Debug Info:
Colocation group had the following types and supported devices:
Root Member(assigned_device_name_index_=-1 requested_device_name_='/device:GPU:1' assigned_device_name_='' resource_device_name_='/device:GPU:1' supported_device_types_=[CPU] possible_devices_=[]
Assign: GPU CPU
Identity: GPU CPU XLA_CPU XLA_GPU
VariableV2: CPU
Colocation members, user-requested devices, and framework assigned devices, if any:
inferpy-predict-enabled-w0 (VariableV2) /device:GPU:1
inferpy-predict-enabled-w0/Assign (Assign) /device:GPU:1
inferpy-predict-enabled-w0/read (Identity) /device:GPU:1
Op: VariableV2
Node attrs: shape=[], shared_name="", dtype=DT_BOOL, container=""
Registered kernels:
device='GPU'; dtype in [DT_INT64]
device='GPU'; dtype in [DT_DOUBLE]
device='GPU'; dtype in [DT_FLOAT]
device='GPU'; dtype in [DT_HALF]
device='CPU'
[[node inferpy-predict-enabled-w0 (defined at /usr/local/lib/python3.6/dist-packages/inferpy/models/random_variable.py:420) ]]
Original stack trace for 'inferpy-predict-enabled-w0':
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "/usr/local/lib/python3.6/dist-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/usr/local/lib/python3.6/dist-packages/ipykernel/kernelapp.py", line 505, in start
self.io_loop.start()
File "/usr/local/lib/python3.6/dist-packages/tornado/platform/asyncio.py", line 148, in start
self.asyncio_loop.run_forever()
File "/usr/lib/python3.6/asyncio/base_events.py", line 438, in run_forever
self._run_once()
File "/usr/lib/python3.6/asyncio/base_events.py", line 1451, in _run_once
handle._run()
File "/usr/lib/python3.6/asyncio/events.py", line 145, in _run
self._callback(*self._args)
File "/usr/local/lib/python3.6/dist-packages/tornado/ioloop.py", line 690, in <lambda>
lambda f: self._run_callback(functools.partial(callback, future))
File "/usr/local/lib/python3.6/dist-packages/tornado/ioloop.py", line 743, in _run_callback
ret = callback()
File "/usr/local/lib/python3.6/dist-packages/tornado/gen.py", line 781, in inner
self.run()
File "/usr/local/lib/python3.6/dist-packages/tornado/gen.py", line 742, in run
yielded = self.gen.send(value)
File "/usr/local/lib/python3.6/dist-packages/ipykernel/kernelbase.py", line 365, in process_one
yield gen.maybe_future(dispatch(*args))
File "/usr/local/lib/python3.6/dist-packages/tornado/gen.py", line 209, in wrapper
yielded = next(result)
File "/usr/local/lib/python3.6/dist-packages/ipykernel/kernelbase.py", line 272, in dispatch_shell
yield gen.maybe_future(handler(stream, idents, msg))
File "/usr/local/lib/python3.6/dist-packages/tornado/gen.py", line 209, in wrapper
yielded = next(result)
File "/usr/local/lib/python3.6/dist-packages/ipykernel/kernelbase.py", line 542, in execute_request
user_expressions, allow_stdin,
File "/usr/local/lib/python3.6/dist-packages/tornado/gen.py", line 209, in wrapper
yielded = next(result)
File "/usr/local/lib/python3.6/dist-packages/ipykernel/ipkernel.py", line 294, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "/usr/local/lib/python3.6/dist-packages/ipykernel/zmqshell.py", line 536, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 2848, in run_cell
raw_cell, store_history, silent, shell_futures)
File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 2874, in _run_cell
return runner(coro)
File "/usr/local/lib/python3.6/dist-packages/IPython/core/async_helpers.py", line 67, in _pseudo_sync_runner
coro.send(None)
File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 3049, in run_cell_async
interactivity=interactivity, compiler=compiler, result=result)
File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 3214, in run_ast_nodes
if (yield from self.run_code(code, result)):
File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 3296, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-f66d6dab9fcd>", line 30, in <module>
m = linear_reg(d=2)
File "/usr/local/lib/python3.6/dist-packages/inferpy/models/prob_model.py", line 44, in wrapper
builder=fn
File "/usr/local/lib/python3.6/dist-packages/inferpy/models/prob_model.py", line 72, in __init__
self.vars, self.params = self._build_model()
File "/usr/local/lib/python3.6/dist-packages/inferpy/models/prob_model.py", line 141, in _build_model
self.builder()
File "/usr/local/lib/python3.6/dist-packages/inferpy/util/runtime.py", line 86, in wrapper
return f(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/inferpy/models/prob_model.py", line 42, in fn
return builder(*args, **kwargs)
File "<ipython-input-1-f66d6dab9fcd>", line 7, in linear_reg
w0 = inf.Normal(0, 1, name="w0")
File "/usr/local/lib/python3.6/dist-packages/inferpy/models/random_variable.py", line 375, in func
is_observed, observed_value = _make_predictable_variables(initial_value, rv_name)
File "/usr/local/lib/python3.6/dist-packages/inferpy/models/random_variable.py", line 420, in _make_predictable_variables
name="inferpy-predict-enabled-{name}".format(name=rv_name or "default"))
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/variables.py", line 259, in __call__
return cls._variable_v1_call(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/variables.py", line 220, in _variable_v1_call
shape=shape)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/variables.py", line 198, in <lambda>
previous_getter = lambda **kwargs: default_variable_creator(None, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/variable_scope.py", line 2511, in default_variable_creator
shape=shape)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/variables.py", line 263, in __call__
return super(VariableMetaclass, cls).__call__(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/variables.py", line 1568, in __init__
shape=shape)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/variables.py", line 1728, in _init_from_args
name=name)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/state_ops.py", line 79, in variable_op_v2
shared_name=shared_name)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_state_ops.py", line 1609, in variable_v2
shared_name=shared_name, name=name)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py", line 788, in _apply_op_helper
op_def=op_def)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 3616, in create_op
op_def=op_def)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 2005, in __init__
self._traceback = tf_stack.extract_stack()`