code: def merge_ports(
      conf: List[PortMapping], args: List[PortMapping]
  ) -> Dict[int, PortMapping]:
      unique_ports_constraint([pm.container_port for pm in conf])
      unique_ports_constraint([pm.container_port for pm in args])
  
      ports = {pm.container_port: pm for pm in conf}
      for pm in args:  # override conf
          ports[pm.container_port] = pm
  
      unique_ports_constraint(
          [
              pm.local_port
              for pm in ports.values()
              if pm.local_port is not None
          ]
      )
      return ports
  
imports: import argparse
  import re
  import subprocess
  from typing import Dict, List, Optional, Tuple, Type
  from dstack._internal.cli.utils.common import console
  from dstack._internal.core.errors import ConfigurationError
  from dstack._internal.core.models.configurations import BaseConfiguration, BaseConfigurationWithPorts, ConfigurationType, DevEnvironmentConfiguration, PortMapping, ServiceConfiguration, TaskConfiguration
  from dstack._internal.utils.interpolator import VariablesInterpolator
label_desc: Use image node_id 3 for calling a global function with example usage: merge_ports(conf, args) and returns: ports