INNER CODE UNIT · Python
apply_gradients
bytedance/byteps · byteps/_keras/__init__.py:68
def apply_gradients(self, *args, **kwargs):
if not self._aggregated_gradients:
raise Exception('`apply_gradients()` was called without a call to '
'`get_gradients()` or `_aggregate_gradients`. If you\'re '
'using TensorFlow 2.0, please specify '
'`experimental_run_tf_function=False` in `compile()`.')
return super(self.__class__, self).apply_gradients(*args, **kwargs)
# We dynamically create a new class that inherits from the optimizer that was passed in.
# The goal is to override get_gradients() method with an push_pull implementation.
# This class will have the same name as the optimizer it's wrapping, so that the saved
# model could be easily restored without BytePS.
cls = type(optimizer.__class__.__name__, (optimizer.__class__,),
dict(_DistributedOptimizer.__dict__))
return cls.from_config(optimizer.get_config())
def _eval(backend, op_or_result):