f19ace982075ea009af81f5e9f687cc2276f50ea,scripts/bert/fp16_utils.py,,grad_global_norm,#Any#Any#,24

Before Change


        x = array.reshape((-1,)).astype("float32", copy=False)
        return nd.dot(x, x)

    norm_arrays = [_norm(arr) for arr in arrays]

    // group norm arrays by ctx
    def group_by_ctx(arr_list):
        groups = collections.defaultdict(list)
        for arr in arr_list:
            ctx = arr.context
            groups[ctx].append(arr)
        return groups
    norm_groups = group_by_ctx(norm_arrays)

    // reduce
    ctx, dtype = arrays[0].context, "float32"
    norms = [nd.add_n(*g).as_in_context(ctx) for g in norm_groups.values()]
    total_norm = nd.add_n(*norms).sqrt()
    scale = total_norm / max_norm
    // is_finite = 0 if NaN or Inf, 1 otherwise.
    is_finite = nd.contrib.isfinite(scale)

After Change


        mx.autograd.backward(ls)

    def step(self, batch_size, max_norm=None):
        Makes one step of parameter update. Should be called after
        `fp16_optimizer.backward()`, and outside of `record()` scope.

        Parameters
        ----------
        batch_size : int
            Batch size of data processed. Gradient will be normalized by `1/batch_size`.
            Set this to 1 if you normalized loss manually with `loss = mean(loss)`.
        max_norm : NDArray, optional, default is None
            max value for global 2-norm of gradients.
        
        self.fp32_trainer.allreduce_grads()
        step_size = batch_size * self._scaler.loss_scale
        if max_norm:
            _, ratio, is_finite = nlp.utils.grad_global_norm(self.fp32_trainer._params,
                                                             max_norm * self._scaler.loss_scale)
            step_size = ratio * step_size
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 4

Non-data size: 8

Instances


Project Name: dmlc/gluon-nlp
Commit Name: f19ace982075ea009af81f5e9f687cc2276f50ea
Time: 2020-01-20
Author: 50716238+MoisesHer@users.noreply.github.com
File Name: scripts/bert/fp16_utils.py
Class Name:
Method Name: grad_global_norm


Project Name: mlflow/mlflow
Commit Name: 9163c404a731ce79899287c6e4709c6f9c900f55
Time: 2019-01-25
Author: mani@databricks.com
File Name: mlflow/store/dbmodels/models.py
Class Name:
Method Name: _create_entity


Project Name: snipsco/snips-nlu
Commit Name: 7e3032b51b197e833915bc353e9e063205c0d4f9
Time: 2017-04-07
Author: adrien.ball@snips.net
File Name: snips_nlu/intent_classifier/data_augmentation.py
Class Name:
Method Name: get_regularization_factor


Project Name: cmu-db/ottertune
Commit Name: 9e9c9c7510b6b50c221cefdde9d30c3b058a2620
Time: 2019-12-05
Author: dvanaken@cs.cmu.edu
File Name: server/website/website/models.py
Class Name: SessionKnobManager
Method Name: get_knobs_for_session