Skip to content

Add optional binary observations to Sync - #72

Open
kodexArg wants to merge 1 commit into
edbeeching:mainfrom
kodexArg:obs-binary-encoding
Open

kodexArg wants to merge 1 commit into
edbeeching:mainfrom
kodexArg:obs-binary-encoding

Conversation

@kodexArg

Copy link
Copy Markdown

Part of edbeeching/godot_rl_agents#267: an opt-in way to send training observations as float32 bytes instead of JSON number lists.

What changes

  • New export on Sync: binary_observations, off by default, also settable with --binary_observations.
  • Encoding: when it is on, each training observation that is an Array, PackedFloat32Array or PackedFloat64Array is sent as PackedFloat32Array(value).to_byte_array().hex_encode().
  • Unchanged: keys containing 2d, other value types, the ONNX inference path and the protocol version.

It needs the decoder from edbeeching/godot_rl_agents#268. With the option off, nothing changes.

Why

The per-step cost with many agents is writing and parsing thousands of floats as text. Measured end to end with this branch and the package branch, with Godot 4.7.2 headless and 69 floats per agent:

Agents JSON lists Hex float32 Speedup
1 207 µs 172 µs 1.2x
10 666 µs 448 µs 1.5x
100 5,435 µs 2,355 µs 2.3x

Each case is the median of 3 runs of 1,500 steps. The decoded observations matched bit for bit. Hex is used instead of base64 because hex_encode() is about 7x faster than Marshalls.raw_to_base64() in Godot 4.7, and it is what 2d keys already use.

How it was tested

A minimal project with this Sync and N AIController3D agents that return deterministic observations, driven by the package branch's GodotEnv. Every 50th step, Python compared the decoded values with the expected ones. All runs matched in both modes.

🤖 Generated with Claude Code

New `binary_observations` export (also `--binary_observations` on the
command line), off by default. When enabled, training observations are
sent as hex-encoded float32 bytes instead of JSON number lists, which
removes most of the per-step serialization cost with many agents.
Keys containing "2d" and the ONNX inference path are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant