public IWeightTensor Softmax(IWeightTensor w, bool runGradients = true, bool inPlace = false) { WeightTensor m = w as WeightTensor; WeightTensor res = null; if (inPlace) { res = m.CopyWeightsRef($"{GetHashString(w.Name)}.Softmax"); } else { res = m_weightTensorFactory.CreateWeightTensor(m.Sizes, m_deviceId, name: $"{GetHashString(w.Name)}.Softmax"); } VisualizeNodes(w, res); Ops.Softmax(res.TWeight, m.TWeight); if (m_needsBackprop && runGradients) { Action backward = () => { if (inPlace) { m.TGradient = res.TGradient.CopyRef(); } m.AddSoftmaxGradient(res, inPlace); res.Dispose(); }; this.m_backprop.Add(backward); } return(res); }
public IWeightTensor Softmax(IWeightTensor w, bool bp = true) { WeightTensor m = w as WeightTensor; var res = m_weightTensorFactory.CreateWeightTensor(m.Sizes, m_deviceId, name: $"{GetHashString(w.Name)}.Softmax"); VisualizeNodes(w, res); Ops.Softmax(res.TWeight, m.TWeight); if (this.m_needsBackprop && bp) { Action backward = () => { m.AddSoftmaxGradient(res); res.Dispose(); }; this.m_backprop.Add(backward); } return(res); }
public IWeightMatrix Softmax(IWeightMatrix w, bool bp = true) { WeightTensor m = w as WeightTensor; var res = weightTensorFactory.CreateWeightTensor(m.Rows, m.Columns, deviceId); Ops.Softmax(res.TWeight, m.TWeight); if (this.needs_backprop && bp) { Action backward = () => { // Ops.SoftmaxGrad(m.TGradient, res.TGradient, res.TWeight); m.AddSoftmaxGradient(res); res.Dispose(); }; this.backprop.Add(backward); } return(res); }