cntk.contrib.crosstalk package¶
Crosstalk (Contrib) for debugging/conversion among toolkits
It is the utility to manage variables for debugging/conversion across scripts in different toolkits. With crosstalk, user can define named watch points to variables or parameters, and setting up a work dir. Then crosstalk can save/load variables to corresponding files from python debugger, and compare values using numpy.
-
class
Conv2DArgs
[source]¶ Bases:
cntk.contrib.crosstalk.Conv2DArgs
Args inside Conv2D variable. Conv2D output is in NCHW format
- W
- The numpy ndarray of filter parameter in shape (num_filters, filter_w, filter_h,))
- b
- The numpy ndarray of bias parameter in shape (num_filters,)
-
class
Conv2DAttr
[source]¶ Bases:
cntk.contrib.crosstalk.Conv2DAttr
Attribute for Conv2D variable
- filter_shape
- The filter shape
- num_filters
- Number of filters
-
class
Crosstalk
[source]¶ Bases:
object
Base class of Crosstalk. Please refer to crosstalk unittests for examples of how to exchange/compare values between different toolkits.
-
assign
(name, value=None, load=False, load_name=None)[source]¶ Set value to var, with option to load from working directory
Parameters: - name (str) – Name of the variable to assign
- value – Numpy ndarray of dict of numpy ndarray data to assign to the variable
- load (bool) – True to Load the data from working directory with the matching name, instead of using value. value has to be None when load=True
- load_name (str) – None to load data with the same name, otherwise load with overrided load_name
-
compare
(name, compare_name=None, rtol=1e-05, atol=1e-08, equal_nan=False)[source]¶ Compare var with name to value in file in working directory
Parameters: - name (str) – Name of the variable to compare
- compare_name (str) – Compare to file with compare_name if specified
- rtol (float) – The relative tolerance parameter, as in numpy.isclose()
- atol (float) – The absolute tolerance parameter, as in numpy.isclose()
- equal_nan (bool) – Whether to compare NaNs as equal, as in numpy.isclose()
-
fetch
(name, save=False)[source]¶ Fetch/evaluate var with name and optionally save to working directory
Parameters: - name (str) – Name of the variable to fetch
- save (bool) – Save the data to working directory
-
load
(names)[source]¶ Load variables in list of names
Parameters: names – List of str of variable names to load
-
load_raw_value
(name)[source]¶ Load raw value from npy|pkl file in working directory
Parameters: name (str) – Name of the file to load Returns: loaded data in numpy ndarray or dict of numpy ndarray
-
register_funcs
(var_type, setter=None, getter=None)[source]¶ Register setter/getter functions for a given variable type
Parameters: - var_type – Type of the variable
- setter – Lambda function to set value
- getter – Lambda function to get value
-
reset
()[source]¶ Reset all variables and passes, setter/getter functions for variable types are kept
-
save
(names)[source]¶ Save variables in list of names
Parameters: names – List of str of variable names to save
-
set_workdir
(dir)[source]¶ Set up a working directory for save/load numpy values(.npy) or python data (.pkl)
Parameters: dir (str) – Working directory
-
watch
(var, name, var_type=None, attr=None)[source]¶ Add variables to watch with a unique name.
Parameters: - var – Variable to watch. The type is toolkit specific
- name (str) – A unique name of the watched variable
- var_type – Variable type for set/get value callback. would be type of var if None is specified
- attr – attributes for the variable that would be used when getting/setting values. Could be one of Conv2DAttr/EmbedAttr/RnnAttr
-
-
class
EmbedAttr
[source]¶ Bases:
cntk.contrib.crosstalk.EmbedAttr
Attribute for embedding variable
- dict
- The list of vocabulary of the embedding
- input_dim
- The input dimension of the embedding
-
class
RnnArgs
[source]¶ Bases:
cntk.contrib.crosstalk.RnnArgs
Args inside RNN variable.
- fw_W
- The numpy ndarray of input projection parameter for RNN forward in shape (input_dim, num_gates * hidden_dim)
- fw_H
- The numpy ndarray of hidden projection parameter for RNN forward in shape (hidden_dim, num_gates * hidden_dim)
- fw_b
- The numpy ndarray of bias parameter for RNN forward in shape (num_gates * hidden_dim,)
- bw_W
- The numpy ndarray of input projection parameter for RNN backward in shape (input_dim, num_gates * hidden_dim)
- bw_H
- The numpy ndarray of hidden projection parameter for RNN backward in shape (hidden_dim, num_gates * hidden_dim)
- bw_b
- The numpy ndarray of bias parameter for RNN backward in shape (num_gates * hidden_dim,)
-
class
RnnAttr
[source]¶ Bases:
cntk.contrib.crosstalk.RnnAttr
Attribute for RNN variable
- bidirectional
- True for bidirectional RNN, False for unidirection. Currently only support bidirectional=True
- op_type
- RNN cell type, currently only support ‘lstm’
- input_dim
- Input dimension
- hidden_dim
- Hidden dimension in RNN cell
- forget_bias
- forget gate bias in LSTM