{"record":{"id":"c3c3f72a116a572c","repo":"Unity-Technologies/ml-agents","slug":"sac-does-not-support-sharedactorcritic","errorCode":null,"errorMessage":"SAC does not support SharedActorCritic","messagePattern":"SAC does not support SharedActorCritic","errorType":"exception","errorClass":"UnityTrainerException","httpStatus":null,"severity":"error","filePath":"ml-agents/mlagents/trainers/sac/optimizer_torch.py","lineNumber":131,"sourceCode":"            return q1_out, q2_out\n\n    class TargetEntropy(NamedTuple):\n\n        discrete: List[float] = []  # One per branch\n        continuous: float = 0.0\n\n    class LogEntCoef(nn.Module):\n        def __init__(self, discrete, continuous):\n            super().__init__()\n            self.discrete = discrete\n            self.continuous = continuous\n\n    def __init__(self, policy: TorchPolicy, trainer_settings: TrainerSettings):\n        super().__init__(policy, trainer_settings)\n        reward_signal_configs = trainer_settings.reward_signals\n        reward_signal_names = [key.value for key, _ in reward_signal_configs.items()]\n        if isinstance(policy.actor, SharedActorCritic):\n            raise UnityTrainerException(\"SAC does not support SharedActorCritic\")\n        self._critic = ValueNetwork(\n            reward_signal_names,\n            policy.behavior_spec.observation_specs,\n            policy.network_settings,\n        )\n        hyperparameters: SACSettings = cast(\n            SACSettings, trainer_settings.hyperparameters\n        )\n\n        self.tau = hyperparameters.tau\n        self.init_entcoef = hyperparameters.init_entcoef\n\n        self.policy = policy\n        policy_network_settings = policy.network_settings\n\n        self.tau = hyperparameters.tau\n        self.burn_in_ratio = 0.0\n","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents/mlagents/trainers/sac/optimizer_torch.py#L113-L149","documentation":"UnityTrainerException raised in the SAC optimizer's __init__ when the policy's actor is a SharedActorCritic network. SAC builds its own separate ValueNetwork critic and therefore cannot use the shared actor-critic architecture supported by PPO. The check runs at optimizer construction, so the run fails immediately at startup.","triggerScenarios":"Configuring shared_critic=true (SharedActorCritic actor) in network_settings while using the SAC trainer, e.g.:\nbehavior:\n  network_settings:\n    shared_critic: true\nwith trainer_type: sac.","commonSituations":"Copying a PPO config into an SAC run without removing shared_critic; experimenting with memory/shared networks and not realizing SAC requires a separate critic.","solutions":["Set network_settings.shared_critic to false in your YAML, or remove the shared_critic key (defaults to false).","Switch the trainer to PPO/POCA if you specifically want a shared actor-critic network.","Keep SAC with its default separate critic; tune SAC via separate hyperparameters (buffer_size, learning_rate) instead."],"exampleFix":"# before (SAC YAML)\nnetwork_settings:\n  shared_critic: true\n# after\nnetwork_settings:\n  shared_critic: false","handlingStrategy":"validation","validationCode":"config = yaml.safe_load(open(\"config.yaml\"))\nns = config[\"behavior\"].get(\"network_settings\", {})\nif config[\"behavior\"][\"trainer_type\"] == \"sac\" and ns.get(\"shared_critic\", False):\n    raise ValueError(\"shared_critic is not supported by SAC; set it to false\")","typeGuard":"def sac_config_is_valid(behavior_config: dict) -> bool:\n    if behavior_config.get(\"trainer_type\") != \"sac\":\n        return True\n    return not behavior_config.get(\"network_settings\", {}).get(\"shared_critic\", False)","tryCatchPattern":"from mlagents.trainers.exception import UnityTrainerException\ntry:\n    optimizer = SACTorchOptimizer(policy, trainer_settings)\nexcept UnityTrainerException:\n    trainer_settings.network_settings.shared_critic = False\n    optimizer = SACTorchOptimizer(policy, trainer_settings)","preventionTips":["Never set shared_critic: true in SAC configs","Copy PPO configs into SAC runs only after removing PPO-specific/shared-critic options","Validate YAML configs with the ML-Agents config validator before long training runs"],"tags":["ml-agents","configuration","sac","incompatible-options"],"backgroundTag":"incompatible-config-combination","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}