Description
The model instantiators are bugged if you try to use "concatenate" in the output definition of a model. The documentation clearly states that this should be possible for inputs and outputs.
Below is an example for a failing instatiator.
source = gaussian_model(
observation_space=obs_space,
action_space=act_space,
network=network,
output="concatenate([head_a, head_b])",
return_source=True,
)
Minimal reproduction of the bug in skrl's model instantiator output parser:
skrl_concat_output_bug.py
Root cause: In _parse_output (common.py), the visit_Call method of the NodeTransformer replaces node.func with an ast.Attribute node when it encounters concatenate, but then falls through to the activation function check which assumes node.func is still an ast.Name (i.e. has .id).
Compare with _parse_input, which handles concatenate correctly by returning early before any activation logic.
Fix: Add else to the activation check only runs when the concatenate branch did not fire.
Error Log:
File "/home/jules/thesis/scripts/skrl/train.py", line 273, in main
runner = Runner(env, agent_cfg)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/jules/IsaacLab/lab_env/lib/python3.11/site-packages/skrl/utils/runner/torch/runner.py", line 33, in __init__
self._models = self._generate_models(self._env, copy.deepcopy(self._cfg))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jules/IsaacLab/lab_env/lib/python3.11/site-packages/skrl/utils/runner/torch/runner.py", line 247, in _generate_models
source = model_class(
^^^^^^^^^^^^
File "/home/jules/IsaacLab/lab_env/lib/python3.11/site-packages/skrl/utils/model_instantiators/torch/gaussian.py", line 77, in gaussian_model
containers, output = generate_containers(network, output, embed_output=True, indent=1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jules/IsaacLab/lab_env/lib/python3.11/site-packages/skrl/utils/model_instantiators/torch/common.py", line 288, in generate_containers
output, output_modules, output_size = _parse_output(output)
^^^^^^^^^^^^^^^^^^^^^
File "/home/jules/IsaacLab/lab_env/lib/python3.11/site-packages/skrl/utils/model_instantiators/torch/common.py", line 139, in _parse_output
NodeTransformer().visit(tree)
File "/home/jules/.local/share/uv/python/cpython-3.11.14-linux-x86_64-gnu/lib/python3.11/ast.py", line 418, in visit
return visitor(node)
^^^^^^^^^^^^^
File "/home/jules/.local/share/uv/python/cpython-3.11.14-linux-x86_64-gnu/lib/python3.11/ast.py", line 494, in generic_visit
value = self.visit(value)
^^^^^^^^^^^^^^^^^
File "/home/jules/.local/share/uv/python/cpython-3.11.14-linux-x86_64-gnu/lib/python3.11/ast.py", line 418, in visit
return visitor(node)
^^^^^^^^^^^^^
File "/home/jules/.local/share/uv/python/cpython-3.11.14-linux-x86_64-gnu/lib/python3.11/ast.py", line 503, in generic_visit
new_node = self.visit(old_value)
^^^^^^^^^^^^^^^^^^^^^
File "/home/jules/.local/share/uv/python/cpython-3.11.14-linux-x86_64-gnu/lib/python3.11/ast.py", line 418, in visit
return visitor(node)
^^^^^^^^^^^^^
File "/home/jules/IsaacLab/lab_env/lib/python3.11/site-packages/skrl/utils/model_instantiators/torch/common.py", line 121, in visit_Call
activation = _get_activation_function(node.func.id, as_module=False)
^^^^^^^^^^^^
AttributeError: 'Attribute' object has no attribute 'id'
What skrl version are you using?
2.0.0
What ML framework/library version are you using?
PyTorch
Additional system information
Python 3.11, Ubuntu 22
Description
The model instantiators are bugged if you try to use "concatenate" in the output definition of a model. The documentation clearly states that this should be possible for inputs and outputs.
Below is an example for a failing instatiator.
Minimal reproduction of the bug in skrl's model instantiator output parser:
skrl_concat_output_bug.py
Root cause: In
_parse_output(common.py), thevisit_Callmethod of the NodeTransformer replacesnode.funcwith anast.Attributenode when it encountersconcatenate, but then falls through to the activation function check which assumesnode.funcis still anast.Name(i.e. has.id).Compare with
_parse_input, which handlesconcatenatecorrectly by returning early before any activation logic.Fix: Add
elseto the activation check only runs when the concatenate branch did not fire.Error Log:
What skrl version are you using?
2.0.0
What ML framework/library version are you using?
PyTorch
Additional system information
Python 3.11, Ubuntu 22