Skip to content

Add configurable initial reset for ONNX inference mode (to overcome minor differences between Python server inference and Onnx inference) - #67

Open
stefanfausser wants to merge 1 commit into
edbeeching:mainfrom
stefanfausser:fixes/obs3
Open

Add configurable initial reset for ONNX inference mode (to overcome minor differences between Python server inference and Onnx inference)#67
stefanfausser wants to merge 1 commit into
edbeeching:mainfrom
stefanfausser:fixes/obs3

Conversation

@stefanfausser

@stefanfausser stefanfausser commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

What this PR does:

This PR adds the sync-node export variable initial_reset_onnx_inference. Once this is set to true (default is false), the environments are initially resetted once in Onnx inference mode, same as it happens in the Python server inference (sync node: training mode).

In addition to this, I added a set_pause(true) in _inference_process() which was missing.

The reason for this PR and, thus, the added feature, is to get the same sequence of observations and actions both for Python server inference (sync node: training mode) and Onnx inference.

Together with PR #66, this target can be reached.

How I tested it (on RingPong example):

Both PRs, this and #66, need to be merged and initial_reset_onnx_inference must be set to true. Then a seed needs to be set in the RingPong example in game.gd:

func _ready():
	# randomize()
	seed(777)

Furthermore, a debug output in controller.gd needs to be added (and action value is rounded to avoid suffering from floating point differences between C#-ONNX and Python / Pytorch):

func set_action(action) -> void:
    var move_action_rounded = int(action["move_action"][0] * 1000) / 1000.0
    move_action = clamp(move_action_rounded, -1.0, 1.0)
    print("controller set_action() frames: ", Engine.get_physics_frames(), " move_action: ", move_action_rounded)

Last, Python server inference (training mode) followed by Onnx inference needs to be done for some steps and the debug outputs (log) of the two need to be compared. Optionally, the obs vector values can be printed as well in training and inference functions in the sync node. Expected are the same sequences of action values (and obs values).

I got the same sequence of observations + action values / actions for 100 timesteps with seed 777.

@stefanfausser stefanfausser changed the title Feature: Optionally perform an initial reset once in ONNX inference mode Feature: Added configurable initial reset for ONNX inference mode (to fix minor differences between Python server inference and Onnx inference) Jul 2, 2026
@stefanfausser stefanfausser changed the title Feature: Added configurable initial reset for ONNX inference mode (to fix minor differences between Python server inference and Onnx inference) Added configurable initial reset for ONNX inference mode (to fix minor differences between Python server inference and Onnx inference) Jul 2, 2026
@stefanfausser stefanfausser changed the title Added configurable initial reset for ONNX inference mode (to fix minor differences between Python server inference and Onnx inference) Added configurable initial reset for ONNX inference mode (to overcome minor differences between Python server inference and Onnx inference) Jul 2, 2026
@stefanfausser stefanfausser changed the title Added configurable initial reset for ONNX inference mode (to overcome minor differences between Python server inference and Onnx inference) Add configurable initial reset for ONNX inference mode (to overcome minor differences between Python server inference and Onnx inference) Jul 9, 2026
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