當前位置: 首頁>>代碼示例>>Python>>正文


Python typing.Deque方法代碼示例

本文整理匯總了Python中typing.Deque方法的典型用法代碼示例。如果您正苦於以下問題:Python typing.Deque方法的具體用法?Python typing.Deque怎麽用?Python typing.Deque使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在typing的用法示例。


在下文中一共展示了typing.Deque方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Deque [as 別名]
def __init__(self, bot: Bot):
        super().__init__()

        self.bot = bot

        # Categories
        self.available_category: discord.CategoryChannel = None
        self.in_use_category: discord.CategoryChannel = None
        self.dormant_category: discord.CategoryChannel = None

        # Queues
        self.channel_queue: asyncio.Queue[discord.TextChannel] = None
        self.name_queue: t.Deque[str] = None

        self.name_positions = self.get_names()
        self.last_notification: t.Optional[datetime] = None

        # Asyncio stuff
        self.queue_tasks: t.List[asyncio.Task] = []
        self.ready = asyncio.Event()
        self.on_message_lock = asyncio.Lock()
        self.init_task = self.bot.loop.create_task(self.init_cog()) 
開發者ID:python-discord,項目名稱:bot,代碼行數:24,代碼來源:help_channels.py

示例2: backward

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Deque [as 別名]
def backward(ctx: Context,
                 *grad_output: Tensor,
                 ) -> Tuple[Optional[Tensor], ...]:
        prev_stream = ctx.prev_stream
        next_stream = ctx.next_stream

        grad_input: Deque[Tensor] = deque(maxlen=len(grad_output))
        input_stream = current_stream(get_device(prev_stream))

        with use_stream(prev_stream), use_stream(next_stream):
            for x in reversed(grad_output):
                y = x.to(get_device(prev_stream))
                grad_input.appendleft(y)

                # 'next_stream' is not where 'x' has been allocated.
                record_stream(x, next_stream)
                # 'y' has been allocated on 'prev_stream'.
                # It might be used on the current stream captured as 'input_stream'.
                record_stream(y, input_stream)

        grad_streams: Tuple[Optional[Tensor], ...] = (None, None)
        return grad_streams + tuple(grad_input) 
開發者ID:kakaobrain,項目名稱:torchgpipe,代碼行數:24,代碼來源:copy.py

示例3: save_rng_states

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Deque [as 別名]
def save_rng_states(device: torch.device,
                    rng_states: Deque[RNGStates],
                    ) -> None:
    """:meth:`Checkpoint.forward` captures the current PyTorch's random number
    generator states at CPU and GPU to reuse in :meth:`Recompute.backward`.

    .. seealso:: :ref:`Referential Transparency`

    """
    cpu_rng_state = torch.get_rng_state()

    gpu_rng_state: Optional[ByteTensor]
    if device.type == 'cuda':
        gpu_rng_state = torch.cuda.get_rng_state(device)
    else:
        gpu_rng_state = None

    rng_states.append((cpu_rng_state, gpu_rng_state)) 
開發者ID:kakaobrain,項目名稱:torchgpipe,代碼行數:20,代碼來源:checkpoint.py

示例4: restore_rng_states

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Deque [as 別名]
def restore_rng_states(device: torch.device,
                       rng_states: Deque[RNGStates],
                       ) -> Generator[None, None, None]:
    """:meth:`Recompute.backward` restores the random number generator states
    captured by :func:`save_rng_states` within its context.

    .. seealso:: :ref:`Referential Transparency`

    """
    cpu_rng_state, gpu_rng_state = rng_states.pop()

    gpu_devices: List[torch.device] = []
    if device.type == 'cuda':
        gpu_devices.append(device)

    with torch.random.fork_rng(gpu_devices):
        torch.set_rng_state(cpu_rng_state)
        if gpu_rng_state is not None:
            torch.cuda.set_rng_state(gpu_rng_state, device)
        yield 
開發者ID:kakaobrain,項目名稱:torchgpipe,代碼行數:22,代碼來源:checkpoint.py

示例5: forward

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Deque [as 別名]
def forward(ctx: Context,  # type: ignore
                phony: Tensor,
                recomputed: Deque[Recomputed],
                rng_states: Deque[RNGStates],
                function: Function,
                input_atomic: bool,
                *input: Tensor,
                ) -> TensorOrTensors:
        ctx.recomputed = recomputed
        ctx.rng_states = rng_states

        save_rng_states(input[0].device, ctx.rng_states)

        ctx.function = function
        ctx.input_atomic = input_atomic
        ctx.save_for_backward(*input)

        with torch.no_grad(), enable_checkpointing():
            output = function(input[0] if input_atomic else input)

        return output 
開發者ID:kakaobrain,項目名稱:torchgpipe,代碼行數:23,代碼來源:checkpoint.py


注:本文中的typing.Deque方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。