MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _canonical_to_params

Function _canonical_to_params

tensorflow/python/keras/layers/recurrent_v2.py:1003–1031  ·  view source on GitHub ↗

Utility function convert variable to CuDNN compatible parameter. Note that Keras weights for kernels are different from the CuDNN format. Eg.: ``` Keras CuDNN [[0, 1, 2], <---> [[0, 2, 4], [3, 4, 5]] [1, 3, 5]] ``` If the input weights need to be in

(weights, biases, shape, transpose_weights=False)

Source from the content-addressed store, hash-verified

1001
1002
1003def _canonical_to_params(weights, biases, shape, transpose_weights=False):
1004 """Utility function convert variable to CuDNN compatible parameter.
1005
1006 Note that Keras weights for kernels are different from the CuDNN format. Eg.:
1007
1008 ```
1009 Keras CuDNN
1010 [[0, 1, 2], <---> [[0, 2, 4],
1011 [3, 4, 5]] [1, 3, 5]]
1012 ```
1013
1014 If the input weights need to be in a unified format, then set
1015 `transpose_weights=True` to convert the weights.
1016
1017 Args:
1018 weights: list of weights for the individual kernels and recurrent kernels.
1019 biases: list of biases for individual gate.
1020 shape: the shape for the converted variables that will be feed to CuDNN.
1021 transpose_weights: boolean, whether to transpose the weights.
1022
1023 Returns:
1024 The converted weights that can be feed to CuDNN ops as param.
1025 """
1026 def convert(w):
1027 return array_ops.transpose(w) if transpose_weights else w
1028
1029 weights = [array_ops.reshape(convert(x), shape) for x in weights]
1030 biases = [array_ops.reshape(x, shape) for x in biases]
1031 return array_ops.concat(weights + biases, axis=0)
1032
1033
1034def standard_lstm(inputs, init_h, init_c, kernel, recurrent_kernel, bias,

Callers 2

cudnn_gruFunction · 0.85
cudnn_lstmFunction · 0.85

Calls 3

reshapeMethod · 0.80
convertFunction · 0.70
concatMethod · 0.45

Tested by

no test coverage detected