コード例 #1
0
ファイル: rnn.py プロジェクト: rwth-i6/returnn
def init_theano_devices():
  """
  Only for Theano.

  :rtype: list[Device.Device]|None
  """
  if not BackendEngine.is_theano_selected():
    return None
  from Util import TheanoFlags
  from Config import get_devices_init_args
  from Device import Device
  old_device_config = ",".join(config.list('device', ['default']))
  if config.value("task", "train") == "nop":
    return []
  if "device" in TheanoFlags:
    # This is important because Theano likely already has initialized that device.
    config.set("device", TheanoFlags["device"])
    print("Devices: Use %s via THEANO_FLAGS instead of %s." % (TheanoFlags["device"], old_device_config), file=log.v4)
  dev_args = get_devices_init_args(config)
  assert len(dev_args) > 0
  devices = [Device(**kwargs) for kwargs in dev_args]
  for device in devices:
    while not device.initialized:
      time.sleep(0.25)
  if devices[0].blocking:
    print("Devices: Used in blocking / single proc mode.", file=log.v4)
  else:
    print("Devices: Used in multiprocessing mode.", file=log.v4)
  return devices
コード例 #2
0
ファイル: rnn.py プロジェクト: mtingzhi/returnn
def init_theano_devices():
    """
  Only for Theano.

  :rtype: list[Device.Device]|None
  """
    if not BackendEngine.is_theano_selected():
        return None
    from Util import TheanoFlags
    from Config import get_devices_init_args
    from Device import Device
    old_device_config = ",".join(config.list('device', ['default']))
    if config.value("task", "train") == "nop":
        return []
    if "device" in TheanoFlags:
        # This is important because Theano likely already has initialized that device.
        config.set("device", TheanoFlags["device"])
        print("Devices: Use %s via THEANO_FLAGS instead of %s." %
              (TheanoFlags["device"], old_device_config),
              file=log.v4)
    dev_args = get_devices_init_args(config)
    assert len(dev_args) > 0
    devices = [Device(**kwargs) for kwargs in dev_args]
    for device in devices:
        while not device.initialized:
            time.sleep(0.25)
    if devices[0].blocking:
        print("Devices: Used in blocking / single proc mode.", file=log.v4)
    else:
        print("Devices: Used in multiprocessing mode.", file=log.v4)
    return devices
コード例 #3
0
 def _init_devices(self):
     """
 Initiates the required devices for a config. Same as the funtion initDevices in
 rnn.py.
 :param config:
 :return: A list with the devices used.
 """
     oldDeviceConfig = ",".join(self.config.list('device', ['default']))
     if "device" in TheanoFlags:
         # This is important because Theano likely already has initialized that device.
         config.set("device", TheanoFlags["device"])
         print("Devices: Use %s via THEANO_FLAGS instead of %s." %
               (TheanoFlags["device"], oldDeviceConfig),
               file=log.v4)
     devArgs = get_devices_init_args(self.config)
     assert len(devArgs) > 0
     devices = [Device(**kwargs) for kwargs in devArgs]
     for device in devices:
         while not device.initialized:
             time.sleep(0.25)
     if devices[0].blocking:
         print("Devices: Used in blocking / single proc mode.", file=log.v4)
     else:
         print("Devices: Used in multiprocessing mode.", file=log.v4)
     return devices
コード例 #4
0
ファイル: Server.py プロジェクト: rwth-i6/returnn
 def _init_devices(self):
   """
   Initiates the required devices for a config. Same as the funtion initDevices in
   rnn.py.
   :param config:
   :return: A list with the devices used.
   """
   oldDeviceConfig = ",".join(self.config.list('device', ['default']))
   if "device" in TheanoFlags:
     # This is important because Theano likely already has initialized that device.
     config.set("device", TheanoFlags["device"])
     print("Devices: Use %s via THEANO_FLAGS instead of %s." % (TheanoFlags["device"], oldDeviceConfig), file=log.v4)
   devArgs = get_devices_init_args(self.config)
   assert len(devArgs) > 0
   devices = [Device(**kwargs) for kwargs in devArgs]
   for device in devices:
     while not device.initialized:
       time.sleep(0.25)
   if devices[0].blocking:
     print("Devices: Used in blocking / single proc mode.", file=log.v4)
   else:
     print("Devices: Used in multiprocessing mode.", file=log.v4)
   return devices