Skip to content

Commit 3386245

Browse files
Update TorchSharp to latest version (#6636)
* version update fixes * Path fix for codecov
1 parent e30555c commit 3386245

File tree

9 files changed

+13
-15
lines changed

9 files changed

+13
-15
lines changed

build/ci/job-template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
- ${{ if eq(parameters.nightlyBuild, 'false') }}:
123123
- ${{ if eq(parameters.innerLoop, 'false') }}:
124124
- ${{ if and(eq(parameters.runSpecific, 'false'), eq(parameters.useVSTestTask, 'false')) }}:
125-
- script: set PATH=%PATH%;%USERPROFILE%\.nuget\packages\libtorch-cpu-win-x64\1.11.0.1\runtimes\win-x64\native;%USERPROFILE%\.nuget\packages\torchsharp\0.96.7\runtimes\win-x64\native & ${{ parameters.buildScript }} /p:Build=false -configuration $(_configuration) /p:TargetArchitecture=${{ parameters.architecture }} /p:TestArchitectures=${{ parameters.architecture }} -test -integrationTest /p:Coverage=${{ parameters.codeCoverage }} $(testTargetFramework)
125+
- script: set PATH=%PATH%;%USERPROFILE%\.nuget\packages\libtorch-cpu-win-x64\1.13.0.1\runtimes\win-x64\native;%USERPROFILE%\.nuget\packages\torchsharp\0.99.5\runtimes\win-x64\native & ${{ parameters.buildScript }} /p:Build=false -configuration $(_configuration) /p:TargetArchitecture=${{ parameters.architecture }} /p:TestArchitectures=${{ parameters.architecture }} -test -integrationTest /p:Coverage=${{ parameters.codeCoverage }} $(testTargetFramework)
126126
displayName: Run All Tests.
127127
- ${{ if and(eq(parameters.runSpecific, 'true'), eq(parameters.useVSTestTask, 'false')) }}:
128128
- script: ${{ parameters.buildScript }} /p:Build=false -configuration $(_configuration) /p:TargetArchitecture=${{ parameters.architecture }} /p:TestArchitectures=${{ parameters.architecture }} -test -integrationTest /p:TestRunnerAdditionalArguments='-trait$(spaceValue)Category=RunSpecificTest' /p:Coverage=${{ parameters.codeCoverage }} $(testTargetFramework)

eng/Versions.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<SystemCodeDomVersion>4.5.0</SystemCodeDomVersion>
2222
<SystemCollectionsImmutableVersion>1.5.0</SystemCollectionsImmutableVersion>
2323
<SystemIOFileSystemAccessControl>4.5.0</SystemIOFileSystemAccessControl>
24-
<SystemMemoryVersion>4.5.3</SystemMemoryVersion>
24+
<SystemMemoryVersion>4.5.5</SystemMemoryVersion>
2525
<SystemReflectionEmitLightweightVersion>4.3.0</SystemReflectionEmitLightweightVersion>
2626
<SystemReflectionEmitVersion>4.3.0</SystemReflectionEmitVersion>
2727
<SystemRuntimeCompilerServicesUnsafeVersion>6.0.0</SystemRuntimeCompilerServicesUnsafeVersion>
@@ -56,12 +56,12 @@
5656
<NewtonsoftJsonVersion>13.0.1</NewtonsoftJsonVersion>
5757
<ParquetDotNetVersion>2.1.3</ParquetDotNetVersion>
5858
<PlotlyNETCSharpVersion>0.0.1</PlotlyNETCSharpVersion>
59-
<SharpZipLibVersion>1.3.3</SharpZipLibVersion>
59+
<SharpZipLibVersion>1.4.0</SharpZipLibVersion>
6060
<TensorflowDotNETVersion>0.20.1</TensorflowDotNETVersion>
6161
<TensorFlowMajorVersion>2</TensorFlowMajorVersion>
6262
<TensorFlowVersion>2.3.1</TensorFlowVersion>
63-
<TorchSharpVersion>0.98.3</TorchSharpVersion>
64-
<LibTorchVersion>1.11.0.1</LibTorchVersion>
63+
<TorchSharpVersion>0.99.5</TorchSharpVersion>
64+
<LibTorchVersion>1.13.0.1</LibTorchVersion>
6565
<!-- Build/infrastructure Dependencies -->
6666
<CodecovVersion>1.12.4</CodecovVersion>
6767
<CoverletCollectorVersion>3.1.2</CoverletCollectorVersion>

src/Microsoft.ML.TorchSharp/Microsoft.ML.TorchSharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13+
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
1314
<PackageReference Include="TorchSharp" Version="$(TorchSharpVersion)" />
1415
<PackageReference Include="libtorch-cpu-win-x64" Version="$(LibTorchVersion)" Condition="$([MSBuild]::IsOSPlatform('Windows'))" PrivateAssets="all" />
1516
<PackageReference Include="libtorch-cpu-linux-x64" Version="$(LibTorchVersion)" Condition="$([MSBuild]::IsOSPlatform('Linux'))" PrivateAssets="all" />

src/Microsoft.ML.TorchSharp/NasBert/Models/BaseModel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ internal abstract class BaseModel : torch.nn.Module<torch.Tensor, torch.Tensor,
2020

2121
#pragma warning disable CA1024 // Use properties where appropriate: Modules should be fields in TorchSharp
2222
public abstract TransformerEncoder GetEncoder();
23-
24-
public abstract BaseHead GetHead();
2523
#pragma warning restore CA1024 // Use properties where appropriate
2624

2725
protected BaseModel(NasBertTrainer.NasBertOptions options)

src/Microsoft.ML.TorchSharp/NasBert/Models/NasBertModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ internal class NasBertModel : BaseModel
1515
{
1616
private readonly PredictionHead _predictionHead;
1717

18-
public override BaseHead GetHead() => _predictionHead;
1918
public override TransformerEncoder GetEncoder() => Encoder;
2019

2120
protected readonly TransformerEncoder Encoder;

src/Microsoft.ML.TorchSharp/NasBert/Models/PredictionHead.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Microsoft.ML.TorchSharp.NasBert.Models
1313
{
14-
internal sealed class PredictionHead : BaseHead, torch.nn.IModule<torch.Tensor, torch.Tensor>
14+
internal sealed class PredictionHead : torch.nn.Module<torch.Tensor, torch.Tensor>
1515
{
1616
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "MSML_PrivateFieldName:Private field name not in: _camelCase format", Justification = "Has to match TorchSharp model.")]
1717
private readonly Sequential Classifier;
@@ -34,7 +34,7 @@ public PredictionHead(int inputDim, int numClasses, double dropoutRate)
3434
}
3535

3636
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "MSML_GeneralName:This name should be PascalCased", Justification = "Need to match TorchSharp")]
37-
public torch.Tensor forward(torch.Tensor features)
37+
public override torch.Tensor forward(torch.Tensor features)
3838
{
3939
// TODO: try whitening-like techniques
4040
// take <s> token (equiv. to [CLS])

src/Microsoft.ML.TorchSharp/NasBert/Models/TransformerEncoder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace Microsoft.ML.TorchSharp.NasBert.Models
1818
{
19-
internal sealed class TransformerEncoder : torch.nn.Module, torch.nn.IModule<torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor>
19+
internal sealed class TransformerEncoder : torch.nn.Module<torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor>
2020
{
2121
#pragma warning disable MSML_PrivateFieldName // Private field name not in: _camelCase format Have to match TorchSharp model
2222

@@ -159,7 +159,7 @@ public TransformerEncoder(
159159
}
160160

161161
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "MSML_GeneralName:This name should be PascalCased", Justification = "Need to match TorchSharp.")]
162-
public torch.Tensor forward(
162+
public override torch.Tensor forward(
163163
torch.Tensor tokens,
164164
torch.Tensor segmentLabels = null,
165165
torch.Tensor positions = null)

src/Microsoft.ML.TorchSharp/Utils/ImageUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static void Postprocess(Tensor imgBatch, Tensor classification, Tensor re
5050

5151
for (int i = 0; i < classification.shape[2]; ++i)
5252
{
53-
var scores1 = torch.squeeze(classification[.., .., i]);
53+
var scores1 = torch.squeeze(classification[.., .., i], null);
5454
var scoresOverThresh = scores1 > 0.05;
5555
if (scoresOverThresh.sum().ToSingle() == 0)
5656
{
@@ -59,7 +59,7 @@ public static void Postprocess(Tensor imgBatch, Tensor classification, Tensor re
5959
}
6060

6161
var scores = scores1[scoresOverThresh];
62-
var anchorBoxes1 = torch.squeeze(transformedAnchors);
62+
var anchorBoxes1 = torch.squeeze(transformedAnchors, null);
6363
var anchorBoxes = anchorBoxes1[scoresOverThresh];
6464
var anchorsNmsIdx = Nms(anchorBoxes, scores, overlapThreshold);
6565
var finalAnchorBoxesIndexesValue = torch.ones(anchorsNmsIdx.shape[0], dtype: ScalarType.Int64, device: imgBatch.device).multiply(i);

test/Microsoft.ML.Tests/Microsoft.ML.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474

7575
<ItemGroup Condition="'$(TargetArchitecture)' == 'x64'">
7676
<PackageReference Include="libtorch-cpu-win-x64" Version="$(LibTorchVersion)" Condition="$([MSBuild]::IsOSPlatform('Windows')) AND '$(TargetArchitecture)' == 'x64'" />
77-
<!--<PackageReference Include="TorchSharp-cuda-windows" Version="0.96.8" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />-->
77+
<!--<PackageReference Include="TorchSharp-cuda-windows" Version="0.99.5" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />-->
7878
<PackageReference Include="libtorch-cpu-linux-x64" Version="$(LibTorchVersion)" Condition="$([MSBuild]::IsOSPlatform('Linux')) AND '$(TargetArchitecture)' == 'x64'" />
7979
<PackageReference Include="libtorch-cpu-osx-x64" Version="$(LibTorchVersion)" Condition="$([MSBuild]::IsOSPlatform('OSX')) AND '$(TargetArchitecture)' == 'x64'" />
8080
</ItemGroup>

0 commit comments

Comments
 (0)