Skip to content

Commit

Permalink
Fix weights reload issue
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongkaifu committed Sep 22, 2023
1 parent 1ce1784 commit 5aa6eb5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Seq2SeqSharp/Tools/WeightTensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public int Columns
private Tensor m_TGradient = null;
private static readonly object locker = new object();

private bool releasedWeight = false;
// private bool releasedWeight = false;
private readonly IComputeGraph m_computeGraphToBind;

private string m_GradientSetName = "None";
Expand All @@ -83,10 +83,10 @@ public Tensor TWeight
{
get
{
if (releasedWeight)
{
throw new Exception($"The weight '{Name}' has been released, you cannot access it.");
}
//if (releasedWeight)
//{
// throw new Exception($"The weight '{Name}' has been released, you cannot access it.");
//}

if (m_TWeight == null)
{
Expand Down Expand Up @@ -118,7 +118,7 @@ public Tensor TWeight
}
}
}
releasedWeight = false;
// releasedWeight = false;
}
}
}
Expand Down Expand Up @@ -499,11 +499,11 @@ public void SetWeightArray(float[] v)
halves[i] = new half(v[i]);
}

m_TWeight.SetElementsAsHalf(halves);
TWeight.SetElementsAsHalf(halves);
}
else
{
m_TWeight.SetElementsAsFloat(v);
TWeight.SetElementsAsFloat(v);
}
}

Expand All @@ -514,14 +514,14 @@ public void SetWeightArray(half[] v)
throw new InvalidCastException($"Inconsistent element type in weights '{Name}'");
}

m_TWeight.SetElementsAsHalf(v);
TWeight.SetElementsAsHalf(v);
}

public WeightTensor CopyWeightsRef(string name, bool needGradient, IComputeGraph graphToBind)
{
WeightTensor result = new WeightTensor(Sizes, DeviceId, name, needGradient: needGradient, graphToBind: graphToBind, dtype: m_elementType)
{
m_TWeight = m_TWeight.CopyRef()
TWeight = TWeight.CopyRef()
};

return result;
Expand All @@ -544,7 +544,7 @@ public void ReleaseWeight()
{
m_TWeight.Dispose();
m_TWeight = null;
releasedWeight = true;
// releasedWeight = true;
}
}

Expand Down

0 comments on commit 5aa6eb5

Please sign in to comment.