-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In-Editor Analytics for inference (#4677)
- Loading branch information
Chris Elion
committed
Dec 15, 2020
1 parent
f74faae
commit 49090d0
Showing
14 changed files
with
486 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Unity.MLAgents.Actuators; | ||
using Unity.MLAgents.Sensors; | ||
|
||
namespace Unity.MLAgents.Analytics | ||
{ | ||
internal struct InferenceEvent | ||
{ | ||
/// <summary> | ||
/// Hash of the BehaviorName. | ||
/// </summary> | ||
public string BehaviorName; | ||
public string BarracudaModelSource; | ||
public string BarracudaModelVersion; | ||
public string BarracudaModelProducer; | ||
public string BarracudaPackageVersion; | ||
/// <summary> | ||
/// Whether inference is performed on CPU (0) or GPU (1). | ||
/// </summary> | ||
public int InferenceDevice; | ||
public List<EventObservationSpec> ObservationSpecs; | ||
public EventActionSpec ActionSpec; | ||
public int MemorySize; | ||
public long TotalWeightSizeBytes; | ||
public string ModelHash; | ||
} | ||
|
||
/// <summary> | ||
/// Simplified version of ActionSpec struct for use in analytics | ||
/// </summary> | ||
[Serializable] | ||
internal struct EventActionSpec | ||
{ | ||
public int NumContinuousActions; | ||
public int NumDiscreteActions; | ||
public int[] BranchSizes; | ||
|
||
public static EventActionSpec FromActionSpec(ActionSpec actionSpec) | ||
{ | ||
var branchSizes = actionSpec.BranchSizes ?? Array.Empty<int>(); | ||
return new EventActionSpec | ||
{ | ||
NumContinuousActions = actionSpec.NumContinuousActions, | ||
NumDiscreteActions = actionSpec.NumDiscreteActions, | ||
BranchSizes = branchSizes, | ||
}; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Information about one dimension of an observation. | ||
/// </summary> | ||
[Serializable] | ||
internal struct EventObservationDimensionInfo | ||
{ | ||
public int Size; | ||
public int Flags; | ||
} | ||
|
||
/// <summary> | ||
/// Simplified summary of Agent observations for use in analytics | ||
/// </summary> | ||
[Serializable] | ||
internal struct EventObservationSpec | ||
{ | ||
public string SensorName; | ||
public string CompressionType; | ||
public EventObservationDimensionInfo[] DimensionInfos; | ||
|
||
public static EventObservationSpec FromSensor(ISensor sensor) | ||
{ | ||
var shape = sensor.GetObservationShape(); | ||
var dimInfos = new EventObservationDimensionInfo[shape.Length]; | ||
for (var i = 0; i < shape.Length; i++) | ||
{ | ||
dimInfos[i].Size = shape[i]; | ||
// TODO copy flags when we have them | ||
} | ||
|
||
return new EventObservationSpec | ||
{ | ||
SensorName = sensor.GetName(), | ||
CompressionType = sensor.GetCompressionType().ToString(), | ||
DimensionInfos = dimInfos, | ||
}; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.