Guide to Advanced Setup¶
Using GPUs with InferPy¶
InferPy offers a method, called new_session(gpu_memory_fraction)
,
that creates a new TensorFlow session. The argument
gpu_memory_fraction
is a float number between 0 and 1, that
specifies the percentage of GPU memory to use. If this argument is set
to 0 (default behavior), then only the CPU is used. Otherwise, the GPU
is configured to be used for the new default session.
import inferpy as inf
# The `new_session` function must be called firstly, so every tensor is
# registered in the correct graph and session.
inf.new_session(1.0) # use the 100% of the GPU memory for the computations
Dependencies¶
Note that your environment must be configured to use the GPU correctly. The InferPy
package offers an extra requirement option to install the GPU dependencies. However,
bear in mind that you must install the non-python dependencies by yourself. For more
details see the link TensorFlow-GPU.
To use the extra requirements option in InferPy just use the keyword gpu
:
pip install inferpy[gpu]
Configure default float type¶
Just like in Keras, InferPy allows to specify the default float type: e.g. float16, float32, float64.
The function set_floatx(value)
sets the default float type to value
, being one of the previously described
three options. The effect is that in the creation of Random Variables, the arguments are cast to the default
float type if they are of float type.
Additionally, the function floatx()
can be used to check which default float type is being used.
# by default, the float type is float32
import inferpy as inf
import numpy as np
print(inf.floatx())
print(inf.Normal(np.zeros(5), 1.).dtype) # float32
# change the default float type to float64
inf.set_floatx('float64')
print(inf.floatx())
print(inf.Normal(np.zeros(5), 1.).dtype) # float64