Skip to content
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

[MLA-1634] Compression spec #5164

Merged
merged 11 commits into from
Mar 22, 2021
Merged

[MLA-1634] Compression spec #5164

merged 11 commits into from
Mar 22, 2021

Conversation

chriselion
Copy link
Contributor

@chriselion chriselion commented Mar 19, 2021

Proposed change(s)

Change ISensor interface, and remove ISparseChannelSensor interface.

Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)

Types of change(s)

  • New feature
  • Code refactor
  • Breaking change
  • Documentation update

Checklist

  • Added tests that prove my fix is effective or that my feature works
  • Updated the changelog (if applicable)
  • Updated the documentation (if applicable)
  • Updated the migration guide (if applicable)

Other comments

@@ -488,34 +488,6 @@ public static UnityRLCapabilitiesProto ToProto(this UnityRLCapabilities rlCaps)
};
}

internal static bool IsTrivialMapping(ISensor sensor)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this logic to CompressionSpec

@@ -168,23 +155,6 @@ public void TestGetObservationProtoCapabilities()

}

[Test]
public void TestIsTrivialMapping()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to com.unity.ml-agents/Tests/Editor/Sensor/CompressionSpecTests.cs

Copy link
Contributor

@surfnerd surfnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels so much cleaner. good stuff! :shipit:

@chriselion
Copy link
Contributor Author

@dongruoping I forgot to tag you before - does this look OK with the channel mapping?

Copy link
Contributor

@dongruoping dongruoping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Left a few comments but are more like thoughts on what we can do later.

Comment on lines +54 to 57
public virtual CompressionSpec GetCompressionSpec()
{
return SensorCompressionType.None;
return CompressionSpec.Default();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A potential improvement of this is to have a m_CompressionSpec and return that like we do with m_ObservationSpec.
Not sure if it's worthy though given this looks pretty light weight.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cached the shapes previously, because they required allocating memory. I kept that pattern for the ObservationSpecs - it's not really necessary for performance (struct with InplaceArray, so no allocations), but it's not a bad idea since they shouldn't change at runtime. I don't think it's necessary for CompressionSpecs.

Comment on lines 78 to 81
{
m_SensorCompressionType = sensorCompressionType,
m_CompressedChannelMapping = compressedChannelMapping
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically you can pass in SensorCompressionType.None and non-null mapping?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you can. I think I'll just make this the constructor instead of using a static method.

@@ -233,7 +227,7 @@ internal byte[] CreateEmptyPNG()
}

/// <summary>
/// Constrct stacked CompressedChannelMapping.
/// Construct stacked CompressedChannelMapping.
/// </summary>
internal int[] ConstructStackedCompressedChannelMapping(ISensor wrappedSenesor)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought a bit about moving this to the CompressionSpec constructor, don't think it's necessary here though.
But if one day we add more compression types it might make sense to move this so we can do something like CompressionSpec(PNG, num_layer=4, stacking=2) and have it automatically setup for different compression.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think we can move more utility methods into CompressionSpec (even if they stay internal static). I think I'll leave this here for now, but we can move it later if it makes sense (and there's another use case)

@chriselion chriselion merged commit b2d0956 into main Mar 22, 2021
@delete-merged-branch delete-merged-branch bot deleted the MLA-1634-CompressionSpec-main branch March 22, 2021 18:37
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants