Skip to content

Commit 6427cdf

Browse files
Develop torch 1.13.1 (#5982)
* Bumped PyTorch version to 1.13.1 * Added potential fixes to model overrider TBD at a later date. * Updated changelog.
1 parent 42ab41f commit 6427cdf

File tree

8 files changed

+56
-12
lines changed

8 files changed

+56
-12
lines changed

.github/workflows/nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
python-version: [3.10.x]
4141
include:
4242
- python-version: 3.10.x
43-
pip_constraints: test_constraints_max_version.txt
43+
pip_constraints: test_constraints_version.txt
4444
steps:
4545
- uses: actions/checkout@v2
4646
- name: Set up Python

.github/workflows/pytest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
python-version: [3.10.12]
4141
include:
4242
- python-version: 3.10.12
43-
pip_constraints: test_constraints_max_version.txt
43+
pip_constraints: test_constraints_version.txt
4444
steps:
4545
- uses: actions/checkout@v2
4646
- name: Set up Python

Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using UnityEngine;
44
using Unity.Sentis;
55
using System.IO;
6-
using Unity.Sentis.ONNX;
76
using Unity.MLAgents;
87
using Unity.MLAgents.Policies;
98
#if UNITY_EDITOR
@@ -47,7 +46,6 @@ public class ModelOverrider : MonoBehaviour
4746
// Cached loaded ModelAssets, with the behavior name as the key.
4847
Dictionary<string, ModelAsset> m_CachedModels = new Dictionary<string, ModelAsset>();
4948

50-
5149
// Max episodes to run. Only used if > 0
5250
// Will default to 1 if override models are specified, otherwise 0.
5351
int m_MaxEpisodes;
@@ -120,6 +118,7 @@ void GetAssetPathFromCommandLine()
120118
{
121119
return;
122120
}
121+
123122
var maxEpisodes = 0;
124123
var timeoutSeconds = 0;
125124

@@ -148,6 +147,7 @@ void GetAssetPathFromCommandLine()
148147
EditorApplication.isPlaying = false;
149148
#endif
150149
}
150+
151151
m_OverrideExtensions.Add(overrideExtension);
152152
}
153153
else if (args[i] == k_CommandLineQuitAfterEpisodesFlag && i < args.Length - 1)
@@ -276,11 +276,23 @@ public ModelAsset GetModelForBehaviorName(string behaviorName)
276276
if (rawModel == null)
277277
{
278278
Debug.Log($"Couldn't load model file(s) for {behaviorName} in {m_BehaviorNameOverrideDirectory} (full path: {Path.GetFullPath(m_BehaviorNameOverrideDirectory)}");
279+
279280
// Cache the null so we don't repeatedly try to load a missing file
280281
m_CachedModels[behaviorName] = null;
281282
return null;
282283
}
283284

285+
// TODO enable this when we have a decision on supporting loading/converting an ONNX model directly into a ModelAsset
286+
// ModelAsset asset;
287+
// if (isOnnx)
288+
// {
289+
// var modelName = Path.Combine(m_BehaviorNameOverrideDirectory, $"{behaviorName}.onnx");
290+
// asset = LoadOnnxModel(modelName);
291+
// }
292+
// else
293+
// {
294+
// asset = LoadSentisModel(rawModel);
295+
// }
284296
// var asset = isOnnx ? LoadOnnxModel(rawModel) : LoadSentisModel(rawModel);
285297
var asset = LoadSentisModel(rawModel);
286298
asset.name = assetName;
@@ -296,6 +308,41 @@ ModelAsset LoadSentisModel(byte[] rawModel)
296308
return asset;
297309
}
298310

311+
// TODO enable this when we have a decision on supporting loading/converting an ONNX model directly into a ModelAsset
312+
// ModelAsset LoadOnnxModel(string modelName)
313+
// {
314+
// Debug.Log($"Loading model for override: {modelName}");
315+
// var converter = new ONNXModelConverter(true);
316+
// var directoryName = Path.GetDirectoryName(modelName);
317+
// var model = converter.Convert(modelName, directoryName);
318+
// var asset = ScriptableObject.CreateInstance<ModelAsset>();
319+
// var assetData = ScriptableObject.CreateInstance<ModelAssetData>();
320+
// var descStream = new MemoryStream();
321+
// ModelWriter.SaveModelDesc(descStream, model);
322+
// assetData.value = descStream.ToArray();
323+
// assetData.name = "Data";
324+
// assetData.hideFlags = HideFlags.HideInHierarchy;
325+
// descStream.Close();
326+
// descStream.Dispose();
327+
// asset.modelAssetData = assetData;
328+
// var weightStreams = new List<MemoryStream>();
329+
// ModelWriter.SaveModelWeights(weightStreams, model);
330+
//
331+
// asset.modelWeightsChunks = new ModelAssetWeightsData[weightStreams.Count];
332+
// for (int i = 0; i < weightStreams.Count; i++)
333+
// {
334+
// var stream = weightStreams[i];
335+
// asset.modelWeightsChunks[i] = ScriptableObject.CreateInstance<ModelAssetWeightsData>();
336+
// asset.modelWeightsChunks[i].value = stream.ToArray();
337+
// asset.modelWeightsChunks[i].name = "Data";
338+
// asset.modelWeightsChunks[i].hideFlags = HideFlags.HideInHierarchy;
339+
// stream.Close();
340+
// stream.Dispose();
341+
// }
342+
//
343+
// return asset;
344+
// }
345+
299346
// TODO this should probably be deprecated since Sentis does not support direct conversion from byte arrays
300347
// ModelAsset LoadOnnxModel(byte[] rawModel)
301348
// {
@@ -317,7 +364,6 @@ ModelAsset LoadSentisModel(byte[] rawModel)
317364
// return asset;
318365
// }
319366

320-
321367
/// <summary>
322368
/// Load the ModelAsset file from the specified path, and give it to the attached agent.
323369
/// </summary>
@@ -369,12 +415,12 @@ void OverrideModel()
369415
{
370416
Debug.LogWarning(overrideError);
371417
}
418+
372419
Application.Quit(1);
373420
#if UNITY_EDITOR
374421
EditorApplication.isPlaying = false;
375422
#endif
376423
}
377-
378424
}
379425
}
380426
}

com.unity.ml-agents/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to
99
## [Unreleased]
1010
### Major Changes
1111
#### com.unity.ml-agents / com.unity.ml-agents.extensions (C#)
12+
- Updated to PyTorch 1.13.1
1213
- Deprecated support for Python 3.8.x and 3.9.x
1314
- Upgraded ML-Agents to Sentis 1.2.0-exp.2 (#)
1415
- The minimum supported Unity version was updated to 2022.3. (#)

ml-agents/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def run(self):
6262
"Pillow>=4.2.1",
6363
"protobuf>=3.6,<3.20",
6464
"pyyaml>=3.1.0",
65-
"torch>=1.8.0,<=1.11.0",
65+
"torch>=1.13.1",
6666
"tensorboard>=2.14",
6767
# adding six explicit dependency since tensorboard needs it but doesn't declare it as a dep
6868
"six>=1.16",
@@ -72,6 +72,7 @@ def run(self):
7272
"attrs>=19.3.0",
7373
"huggingface_hub>=0.14",
7474
'pypiwin32==223;platform_system=="Windows"',
75+
"onnx==1.12.0",
7576
],
7677
python_requires=">=3.10.1,<=3.10.12",
7778
entry_points={

test_constraints_mid_version.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

test_constraints_min_version.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# pip constraints to use the *highest* versions allowed in ml-agents/setup.py
22
# For projects with upper bounds, we should periodically update this list to the latest
3-
torch==1.11.0
3+
torch==1.13.1

0 commit comments

Comments
 (0)