<commit_before>import atexit

import six

from cupy.cuda import cublas
from cupy.cuda import runtime


class Device(object):

    """Object that represents a CUDA device.

    This class provides some basic manipulations on CUDA devices.

    It supports the context protocol. For example, the following code is an
    example of temporarily switching the current device::

       with Device(0):
           do_something_on_device_0()

    After the *with* statement gets done, the current device is reset to the
    original one.

    Args:
        device (int or cupy.cuda.Device): Index of the device to manipulate. Be
            careful that the device ID (a.k.a. GPU ID) is zero origin. If it is
            a Device object, then its ID is used. The current device is
            selected by default.

    Attributes:
        id (int): ID of this device.

    """
    _cublas_handles = {}

    def __init__(self, device=None):
        if device is None:
            self.id = runtime.getDevice()
        else:
            self.id = int(device)

        self._device_stack = []

    def __int__(self):
        return self.id

    def __enter__(self):
        dev = Device()
        if dev == self:
            dev = None
        else:
            self.use()
        self._device_stack.append(dev)
        return self

    def __exit__(self, *args):
        dev = self._device_stack.pop()
        if dev is not None:
            dev.use()

    def __repr__(self):
        return '<CUDA Device %d>' % self.id

    def use(self):
        """Makes this device current.

        If you want to switch a device temporarily, use the *with* statement.

        """
        runtime.setDevice(self.id)<commit_msg>Fix device bug<commit_after>import atexit

import six

from cupy.cuda import cublas
from cupy.cuda import runtime


class Device(object):

    """Object that represents a CUDA device.

    This class provides some basic manipulations on CUDA devices.

    It supports the context protocol. For example, the following code is an
    example of temporarily switching the current device::

       with Device(0):
           do_something_on_device_0()

    After the *with* statement gets done, the current device is reset to the
    original one.

    Args:
        device (int or cupy.cuda.Device): Index of the device to manipulate. Be
            careful that the device ID (a.k.a. GPU ID) is zero origin. If it is
            a Device object, then its ID is used. The current device is
            selected by default.

    Attributes:
        id (int): ID of this device.

    """
    _cublas_handles = {}

    def __init__(self, device=None):
        if device is None:
            self.id = runtime.getDevice()
        else:
            self.id = int(device)

        self._device_stack = []

    def __int__(self):
        return self.id

    def __enter__(self):
        dev = Device()
        self._device_stack.append(dev)
        if dev != self:
            dev.use()
        return self

    def __exit__(self, *args):
        self._device_stack.pop().use()

    def __repr__(self):
        return '<CUDA Device %d>' % self.id

    def use(self):
        """Makes this device current.

        If you want to switch a device temporarily, use the *with* statement.

        """
        runtime.setDevice(self.id)
{'fraction_non_alphanumeric': 0.08110543706818865, 'fraction_numerical': 0.0012015620306398318, 'mean_word_length': 2.0522456461961505, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6771638', 'n_tokens_mistral': 952, 'n_tokens_neox': 904, 'n_words': 357}