do_merge_lookup

Function

Merges the lookup operation on tables that are queried for multiple times in automatic graph modification mode.

In the model, this function is executed using patch in Optimizer.compute_gradients () to ensure that the gradient and computational graph are correct during training. During evaluation, this function is executed in the graph modification phase.

Prototype

1
from mx_rec.graph.merge_lookup import do_merge_lookup

Parameters

Parameter

Type

Mandatory/Optional

Description

is_train

bool

Mandatory

Whether the training mode is used.

  • True: training mode (train).
  • False: evaluation mode (eval).

Example

For example, in train mode, tf.gradients is used for all gradient calculation. In this case, do_merge_lookup needs to be proactively called.

1
2
3
4
5
from mx_rec.graph.merge_lookup import do_merge_lookup
do_merge_lookup(is_train=True)
sparse_grads = tf.gradients(loss, sparse_variables)
grads_and_vars = [(grad, variable) for grad, variable in zip(sparse_grads, sparse_variables)]
optimizer.apply_gradients(grads_and_vars)