当前位置: 首页>>代码示例>>Python>>正文


Python multiprocessing.Lock方法代码示例

本文整理汇总了Python中torch.multiprocessing.Lock方法的典型用法代码示例。如果您正苦于以下问题:Python multiprocessing.Lock方法的具体用法?Python multiprocessing.Lock怎么用?Python multiprocessing.Lock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在torch.multiprocessing的用法示例。


在下文中一共展示了multiprocessing.Lock方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from torch import multiprocessing [as 别名]
# 或者: from torch.multiprocessing import Lock [as 别名]
def __init__(self, data_scheme, n_bs, n_t, n_agents, batch_size, is_cuda=True, is_shared_mem=True, logging_struct=None):
        self.buffer = BatchEpisodeBuffer(data_scheme=data_scheme,
                                             n_bs=n_bs,
                                             n_t=n_t,
                                             n_agents=n_agents,
                                             is_cuda=is_cuda,
                                             is_shared_mem=True)


        if is_cuda:
            self._to_cuda()
        if is_shared_mem:
            self._to_shared_mem()
        self.queue_head_pos = 0
        self.lock = mp.Lock() # TODO: could make locks more granular!
        self.len = 0
        pass 
开发者ID:schroederdewitt,项目名称:mackrl,代码行数:19,代码来源:replay_buffer.py

示例2: create

# 需要导入模块: from torch import multiprocessing [as 别名]
# 或者: from torch.multiprocessing import Lock [as 别名]
def create(cls):
        """Singleton factory."""
        if not hasattr(cls, 'length_to_eps'):
            # Maps episode length to list of episodes
            cls.length_to_eps = {}
            # Set of episode indices already in the cache
            cls.ep_indices = set()
            # List of batches if popping batches
            cls.batches = []
            # If all episodes have been loaded into memory
            cls.load_complete = Value(ctypes.c_bool, False)
            # Lock to access batches
            cls.batches_lock = Lock()
            # Lock to access length_to_eps
            cls.cache_lock = Lock()
            # Lock for condition variables
            cls.fill_cache_lock = RLock()
            # Condition notifying Loader to add to cache
            cls.add_to_cache_cv = Condition(lock=cls.fill_cache_lock)
            # Condition notifying teacher that cache has episodes
            cls.cache_filled_cv = Condition(lock=cls.fill_cache_lock) 
开发者ID:natashamjaques,项目名称:neural_chat,代码行数:23,代码来源:pytorch_data_teacher.py

示例3: __init__

# 需要导入模块: from torch import multiprocessing [as 别名]
# 或者: from torch.multiprocessing import Lock [as 别名]
def __init__(self, val=True):
        self.val = mp.Value("b", False)
        self.lock = mp.Lock() 
开发者ID:llSourcell,项目名称:OpenAI_Five_vs_Dota2_Explained,代码行数:5,代码来源:utils.py

示例4: __init__

# 需要导入模块: from torch import multiprocessing [as 别名]
# 或者: from torch.multiprocessing import Lock [as 别名]
def __init__(self):
    self.val = mp.Value('i', 0)
    self.lock = mp.Lock() 
开发者ID:Kaixhin,项目名称:Dist-A3C,代码行数:5,代码来源:utils.py

示例5: __init__

# 需要导入模块: from torch import multiprocessing [as 别名]
# 或者: from torch.multiprocessing import Lock [as 别名]
def __init__(self, args):
        super(SharedMemory, self).__init__(args)

        # params for this memory

        # setup
        self.pos = mp.Value('l', 0)
        self.full = mp.Value('b', False)

        if self.tensortype == torch.FloatTensor:
            self.state0s = torch.zeros((self.memory_size, ) + tuple(self.state_shape), dtype=torch.float32)
            self.state1s = torch.zeros((self.memory_size, ) + tuple(self.state_shape), dtype=torch.float32)
        elif self.tensortype == torch.ByteTensor:
            self.state0s = torch.zeros((self.memory_size, ) + tuple(self.state_shape), dtype=torch.uint8)
            self.state1s = torch.zeros((self.memory_size, ) + tuple(self.state_shape), dtype=torch.uint8)
        self.actions = torch.zeros( self.memory_size, self.action_shape)
        self.rewards = torch.zeros( self.memory_size, self.reward_shape)
        self.gamma1s = torch.zeros( self.memory_size, self.gamma_shape)
        self.terminal1s = torch.zeros(self.memory_size, self.terminal_shape)

        self.state0s.share_memory_()
        self.actions.share_memory_()
        self.rewards.share_memory_()
        self.gamma1s.share_memory_()
        self.state1s.share_memory_()
        self.terminal1s.share_memory_()

        self.memory_lock = mp.Lock() 
开发者ID:jingweiz,项目名称:pytorch-distributed,代码行数:30,代码来源:shared_memory.py

示例6: __init__

# 需要导入模块: from torch import multiprocessing [as 别名]
# 或者: from torch.multiprocessing import Lock [as 别名]
def __init__(self, data):
    self.lock = mp.Lock()
    self.data = mp.Value("i", data) 
开发者ID:mjendrusch,项目名称:torchsupport,代码行数:5,代码来源:data.py

示例7: __init__

# 需要导入模块: from torch import multiprocessing [as 别名]
# 或者: from torch.multiprocessing import Lock [as 别名]
def __init__(self, x, y):
    self.ctrl = ReadWriteControl(self)
    self.ctrl_flick = mp.Lock()
    self.which_buffer = mp.Value("l", 0)
    self.buffers = [x, y] 
开发者ID:mjendrusch,项目名称:torchsupport,代码行数:7,代码来源:buffer.py

示例8: __init__

# 需要导入模块: from torch import multiprocessing [as 别名]
# 或者: from torch.multiprocessing import Lock [as 别名]
def __init__(self, owner):
    self.owner = owner
    self.read_lock = mp.Lock()
    self.write_lock = mp.Lock()
    self.read_count = mp.Value("l", 0)
    self.read_count.value = 0

    self.timestamp = mp.Value("l", 0)
    self.local_timestamp = 0 
开发者ID:mjendrusch,项目名称:torchsupport,代码行数:11,代码来源:control.py

示例9: __init__

# 需要导入模块: from torch import multiprocessing [as 别名]
# 或者: from torch.multiprocessing import Lock [as 别名]
def __init__(self, grad_norm, optimizer, scheduler):
        self.optimizer : torch.optim.Optimizer = optimizer
        self.scheduler = scheduler
        self.grad_norm = grad_norm
        self.global_step = torch.tensor(0)
        self.lock = mp.Lock() 
开发者ID:jkulhanek,项目名称:visual-navigation-agent-pytorch,代码行数:8,代码来源:training.py

示例10: __init__

# 需要导入模块: from torch import multiprocessing [as 别名]
# 或者: from torch.multiprocessing import Lock [as 别名]
def __init__(self):
        self.val = mp.Value('i', 0)
        self.lock = mp.Lock() 
开发者ID:Feryal,项目名称:a3c-mujoco,代码行数:5,代码来源:utils.py

示例11: create

# 需要导入模块: from torch import multiprocessing [as 别名]
# 或者: from torch.multiprocessing import Lock [as 别名]
def create(cls):
        if not hasattr(cls, 'length_to_eps'):
            # Maps episode length to list of episodes
            cls.length_to_eps = {}
        if not hasattr(cls, 'ep_indices'):
            # Set of episode indices already in the cache
            cls.ep_indices = set()
        if not hasattr(cls, 'batches'):
            # List of batches if popping batches
            cls.batches = []
        if not hasattr(cls, 'load_complete'):
            # If all episodes have been loaded into memory
            cls.load_complete = Value(ctypes.c_bool, False)
        if not hasattr(cls, 'batches_lock'):
            # Lock to access batches
            cls.batches_lock = Lock()
        if not hasattr(cls, 'cache_lock'):
            # Lock to access length_to_eps
            cls.cache_lock = Lock()
        if not hasattr(cls, 'fill_cache_lock'):
            # Lock for condition variables
            cls.fill_cache_lock = RLock()
        if not hasattr(cls, 'add_to_cache_cv'):
            # Condition notifying Loader to add to cache
            cls.add_to_cache_cv = Condition(lock=cls.fill_cache_lock)
        if not hasattr(cls, 'cache_filled_cv'):
            # Condition notifying teacher that cache has episodes
            cls.cache_filled_cv = Condition(lock=cls.fill_cache_lock) 
开发者ID:THUDM,项目名称:KBRD,代码行数:30,代码来源:pytorch_data_teacher.py

示例12: __init__

# 需要导入模块: from torch import multiprocessing [as 别名]
# 或者: from torch.multiprocessing import Lock [as 别名]
def __init__(self):
        self.val = mp.Value("b", False)
        self.lock = mp.Lock() 
开发者ID:TianhongDai,项目名称:distributed-ppo,代码行数:5,代码来源:utils.py

示例13: __init__

# 需要导入模块: from torch import multiprocessing [as 别名]
# 或者: from torch.multiprocessing import Lock [as 别名]
def __init__(self,
                 env_name,
                 env_kwargs,
                 batch_size,
                 policy,
                 baseline,
                 env=None,
                 seed=None,
                 num_workers=1):
        super(MultiTaskSampler, self).__init__(env_name,
                                               env_kwargs,
                                               batch_size,
                                               policy,
                                               seed=seed,
                                               env=env)

        self.num_workers = num_workers

        self.task_queue = mp.JoinableQueue()
        self.train_episodes_queue = mp.Queue()
        self.valid_episodes_queue = mp.Queue()
        policy_lock = mp.Lock()

        self.workers = [SamplerWorker(index,
                                      env_name,
                                      env_kwargs,
                                      batch_size,
                                      self.env.observation_space,
                                      self.env.action_space,
                                      self.policy,
                                      deepcopy(baseline),
                                      self.seed,
                                      self.task_queue,
                                      self.train_episodes_queue,
                                      self.valid_episodes_queue,
                                      policy_lock)
            for index in range(num_workers)]

        for worker in self.workers:
            worker.daemon = True
            worker.start()

        self._waiting_sample = False
        self._event_loop = asyncio.get_event_loop()
        self._train_consumer_thread = None
        self._valid_consumer_thread = None 
开发者ID:tristandeleu,项目名称:pytorch-maml-rl,代码行数:48,代码来源:multi_task_sampler.py

示例14: per_step

# 需要导入模块: from torch import multiprocessing [as 别名]
# 或者: from torch.multiprocessing import Lock [as 别名]
def per_step(valLoader,
             model,
             criterion,
             downsamplingFactor):

    model.eval()
    criterion.eval()

    avgPER = 0
    varPER = 0
    nItems = 0

    print("Starting the PER computation through beam search")
    bar = progressbar.ProgressBar(maxval=len(valLoader))
    bar.start()

    for index, data in enumerate(valLoader):

        bar.update(index)

        with torch.no_grad():
            seq, sizeSeq, phone, sizePhone = prepare_data(data)
            c_feature = model(seq)
            sizeSeq = sizeSeq / downsamplingFactor
            predictions = torch.nn.functional.softmax(criterion.getPrediction(c_feature),
                                                      dim=2).cpu()
            c_feature = c_feature
            phone = phone.cpu()
            sizeSeq = sizeSeq.cpu()
            sizePhone = sizePhone.cpu()

            mutex = Lock()
            manager = Manager()
            poolData = manager.list()

            processes = []
            for b in range(sizeSeq.size(0)):
                l_ = min(sizeSeq[b] // 4, predictions.size(1))
                s_ = sizePhone[b]
                p = torch.multiprocessing.Process(target=get_local_per,
                                                  args=(poolData, mutex, predictions[b, :l_].view(l_, -1).numpy(),
                                                        phone[b, :s_].view(-1).numpy().astype(np.int32), criterion.BLANK_LABEL))
                p.start()
                processes.append(p)
            for p in processes:
                p.join()

            avgPER += sum([x for x in poolData])
            varPER += sum([x*x for x in poolData])
            nItems += len(poolData)

    bar.finish()

    avgPER /= nItems
    varPER /= nItems

    varPER -= avgPER**2
    print(f"Average PER {avgPER}")
    print(f"Standard deviation PER {math.sqrt(varPER)}") 
开发者ID:facebookresearch,项目名称:libri-light,代码行数:61,代码来源:seq_alignment.py


注:本文中的torch.multiprocessing.Lock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。