The TFCompiler class#
Aliases#
halerium.core.compiler.TFCompiler
- class TFCompiler(tf_graph=None, tf_float_type=None, tf_int_type=None, tf_random_seed=None)#
The halerium TensorFlow compiler class.
The halerium TensorFlow compiler class.
This compiler compiles a graph of halerium Operators into a graph of TensorFlow Tensors and then runs TensorFlow on the compiled graph to perform computations on the halerium graph.
- Parameters:
tf_graph (tensorflow.Graph, optional) – The TensorFlow Graph to hold the compiled graph. All Tensors created by the compiler will be placed in this Graph. If no Graph is provided, the compiler will create an empty Graph, which is recommended. The default is None.
tf_float_type (tensorflow.DType, optional) – The TensorFlow DType to use for the floating-point Tensors. The default is tensorflow.float64.
tf_int_type (tensorflow.DType, optional) – The TensorFlow DType to use for the integer Tensors. The default is tensorflow.int32.
tf_random_seed (int, optional) – The random seed to be set within the tf_graph. The default is None.
- compile(operators, fetches=(), warn_if_compiled=True)#
Compile.
Compile operators, i.e. create their TF tensor representations, and collect the results into a compiled_graph. These Operators can then be evaluated at will. It is recommended to execute this function only once per Compiler instance.
- Parameters:
operators (OperatorBase, collections.abc.Iterable) – The (list of) Operator(s) to be converted to Tensors.
fetches (OperatorBase, collections.abc.Iterable) – Container structure of Operators for which the Tensors are to be returned. The argument is passed to a call of get_fetches, which can also be called explicitly after compiling.
warn_if_compiled (bool) – Whether to warn if already compiled. The default is True.
- Returns:
the same container structure as the parameter fetches, but with the Tensors instead of the Operators.
- Return type:
converted_fetches
- property compiled_graph#
- create_function(input_ops, output_ops)#
Create function.
Create function that evaluates a dict of output ops with respect to a dict of Placeholder input ops. The resulting function will accept a dict with the same keys as input_ops but with numpy arrays as values and return a dict with the same keys as output_ops but with numpy arrays as values.
- Parameters:
input_ops (dict) – The input operators for the function. A dictionary with Operators as values.
output_ops (dict) – The output operators for the function. A dictionary with Operators as values.
- Raises:
NotCompiledErrors – if not compiled yet.
- Returns:
function – The created function. A function taking a dictionary with the same keys as input_ops, and the values for these ops as numpy arrays.
- Return type:
callable
- get_fetches(fetches)#
Get fetches.
- Parameters:
fetches (Operator, collections.abc.Iterable) – Container structure of Operators for which the Tensors are to be returned. The container structure can be nested (e.g. a dict of lists). Its contents are crawled for Operators (dict keys are left unchanged).
- Raises:
NotCompiledError – if not compiled yet.
NotCompiledError – if an operator instance from fetches is unknown to the compiler.
- Returns:
converted_fetches – the same container structure as the parameter fetches, but with the Tensors instead of the Operators.
- Return type:
tensorflow.Tensor, collections.abc.Iterable
- reset(tf_graph=None, tf_float_type=None, tf_random_seed=None)#
Reset.
- Parameters:
tf_graph (tensorflow.Graph, optional) – The TensorFlow Graph to hold the compiled graph. All Tensors created by the compiler will be placed in this Graph. If no Graph is provided, the compiler will create an empty Graph, which is recommended. The default is None.
tf_float_type (tensorflow.DType, optional) – The TensorFlow DType to use for the floating-point Tensors. The default is tensorflow.float64
tf_random_seed (int, optional) – The random seed to be set within the tf_graph. The default is None.
- run_function(input_ops, output_ops, input_values)#
Run function.
Create a function using create_function and execute it immediately with the provided input_values.
- Parameters:
input_ops (dict) – The input operators of the graph… A dictionary with Operators as values.
output_ops (dict) – A dictionary with Operators as values.
input_values (dict) – a dictionary with the same keys as input_ops, and the values for these ops as numpy arrays.
- Raises:
NotCompiledError – if not compiled yet.
- Returns:
output_values – a dictionary holding the output values as numpy arrays.
- Return type:
dict