Skip to content

update torchsharp to 0.105.0 #7416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
<TorchSharpPyBridgeVersion>1.4.1</TorchSharpPyBridgeVersion>
<AutoGenVersion>0.1.0</AutoGenVersion>
<SemanticKernelVersion>1.15.0</SemanticKernelVersion>
<TorchSharpVersion>0.102.7</TorchSharpVersion>
<LibTorchVersion>2.2.1.1</LibTorchVersion>
<TorchSharpVersion>0.105.0</TorchSharpVersion>
<LibTorchVersion>2.5.1</LibTorchVersion>
<!-- Build/infrastructure Dependencies -->
<CodecovVersion>1.12.4</CodecovVersion>
<CoverletCollectorVersion>6.0.2</CoverletCollectorVersion>
Expand Down
16 changes: 8 additions & 8 deletions src/Microsoft.ML.GenAI.Core/Module/QuantizedLinear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public override Tensor forward(Tensor input)
{
// 8bit quantization
using var dispose = torch.NewDisposeScope();
var weight = this.get_buffer("8bit_weight").to(ScalarType.Float32);
var zeroPoint = this.get_buffer("zeroPoint").to(ScalarType.Float32);
var scale = this.get_buffer("scale").to(ScalarType.Float32);
var weight = this.get_buffer("8bit_weight")!.to(ScalarType.Float32);
var zeroPoint = this.get_buffer("zeroPoint")!.to(ScalarType.Float32);
var scale = this.get_buffer("scale")!.to(ScalarType.Float32);
var restoreWeight = (weight - zeroPoint.view(-1, 1)) / scale.view(-1, 1);
// use float32
var result = torch.matmul(input.to(ScalarType.Float32), restoreWeight.T);
Expand All @@ -106,17 +106,17 @@ public override Tensor forward(Tensor input)
{
using var dispose = torch.NewDisposeScope();
var weight = this.get_buffer("4bit_weight");
var weightLower = weight % 16;
var weightUpper = weight / 16;
var weightLower = weight! % 16;
var weightUpper = weight! / 16;
weight = torch.cat([weightUpper, weightLower], 0).to(ScalarType.Float32);
weight = weight.view(this._outFeatures, this._inFeatures);
weight -= 8;
var zeroPoint = this.get_buffer("zeroPoint");
var zeroPointLower = zeroPoint % 16;
var zeroPointUpper = zeroPoint / 16;
var zeroPointLower = zeroPoint! % 16;
var zeroPointUpper = zeroPoint! / 16;
zeroPoint = torch.cat([zeroPointUpper, zeroPointLower], 0).to(ScalarType.Float32);
zeroPoint -= 8;
var scale = this.get_buffer("scale").to(ScalarType.Float32);
var scale = this.get_buffer("scale")!.to(ScalarType.Float32);
var restoreWeight = (weight - zeroPoint.view(-1, 1)) / scale.view(-1, 1);
// use float32
var result = torch.matmul(input.to(ScalarType.Float32), restoreWeight.T);
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.GenAI.Core/Module/RotaryEmbedding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public override RotaryEmbeddingOutput forward(RotaryEmbeddingInput input)
var seqLen = input.SeqLen;
// TODO
// can be calculated once and cached
var invFreq = this.get_buffer("inv_freq").to(x.device);
var invFreq = this.get_buffer("inv_freq")!.to(x.device);
var invFreqExpanded = invFreq.unsqueeze(0).unsqueeze(-1);
invFreqExpanded = invFreqExpanded.expand(new long[] { positionIds.shape[0], -1, 1 });
var positionIdsExpanded = positionIds.unsqueeze(1).to(torch.float32);
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.TorchSharp/AutoFormerV2/ConvModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ConvModule : Module<Tensor, Tensor>
public ConvModule(int inChannel, int outChannel, int kernelSize, int stride = 1, int padding = 0, int dilation = 1, bool bias = true, bool useRelu = true)
: base(nameof(ConvModule))
{
this.conv = nn.Conv2d(in_channels: inChannel, out_channels: outChannel, kernelSize: kernelSize, stride: stride, padding: padding, dilation: dilation, bias: bias);
this.conv = nn.Conv2d(in_channels: inChannel, out_channels: outChannel, kernel_size: kernelSize, stride: stride, padding: padding, dilation: dilation, bias: bias);
this.useRelu = useRelu;
if (this.useRelu)
{
Expand Down
Loading