python类available()的实例源码

weight_clip.py 文件源码 项目:ddnn 作者: kunglab 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __call__(self, opt):
        if cuda.available:
            kernel = cuda.elementwise(
                'T low, T high', 
                'T p', 
                'p = (p < low) ? low : (p > high) ? high : p',
                'weight_clip')

        for link in opt.target.links():
            # only apply to binary layers
            if getattr(link,'cname',False):
                for param in link.params():
                    p = param.data
                    with cuda.get_device(p) as dev:
                        if int(dev) == -1:
                            numpy.clip(p, self.low, self.high)
                        else:
                            kernel(self.low, self.high, p)
weight_clip.py 文件源码 项目:binary_net 作者: hillbig 项目源码 文件源码 阅读 57 收藏 0 点赞 0 评论 0
def __call__(self, opt):
        if cuda.available:
            kernel = cuda.elementwise(
                'T low, T high', 
                'T p', 
                'p = (p < low) ? low : (p > high) ? high : p',
                'weight_clip')

        for param in opt.target.params():
            p = param.data
            with cuda.get_device(p) as dev:
                if int(dev) == -1:
                    numpy.clip(p, self.low, self.high)
                else:
                    kernel(self.low, self.high, p)
nonbias_weight_decay.py 文件源码 项目:chainerrl 作者: chainer 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __call__(self, opt):
        if cuda.available:
            kernel = cuda.elementwise(
                'T p, T decay', 'T g', 'g += decay * p', 'weight_decay')

        rate = self.rate
        for name, param in opt.target.namedparams():
            if name == 'b' or name.endswith('/b'):
                continue
            p, g = param.data, param.grad
            with cuda.get_device(p) as dev:
                if int(dev) == -1:
                    g += rate * p
                else:
                    kernel(p, rate, g)
nonbias_weight_decay.py 文件源码 项目:async-rl 作者: muupan 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __call__(self, opt):
        if cuda.available:
            kernel = cuda.elementwise(
                'T p, T decay', 'T g', 'g += decay * p', 'weight_decay')

        rate = self.rate
        for name, param in opt.target.namedparams():
            if name == 'b' or name.endswith('/b'):
                continue
            p, g = param.data, param.grad
            with cuda.get_device(p) as dev:
                if int(dev) == -1:
                    g += rate * p
                else:
                    kernel(p, rate, g)
extensions.py 文件源码 项目:chainer-began 作者: hvy 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def sample(self, trainer):
        x = trainer.updater.sample()
        x = x.data
        if cuda.available and isinstance(x, cuda.ndarray):
            x = cuda.to_cpu(x)
        return x
optimizer.py 文件源码 项目:chainer-deconv 作者: germanRos 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __call__(self, opt):
        if cuda.available:
            kernel = cuda.elementwise(
                'T p, T decay', 'T g', 'g += decay * p', 'weight_decay')

        rate = self.rate
        for param in opt.target.params():
            p, g = param.data, param.grad
            with cuda.get_device(p) as dev:
                if int(dev) == -1:
                    g += rate * p
                else:
                    kernel(p, rate, g)
optimizer.py 文件源码 项目:chainer-deconv 作者: germanRos 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __call__(self, opt):
        if cuda.available:
            kernel = cuda.elementwise(
                'T s, T decay', 'T g', 'g += decay * s', 'lasso')

        rate = self.rate
        for param in opt.target.params():
            p, g = param.data, param.grad
            xp = cuda.get_array_module(p)
            sign = xp.sign(p)
            with cuda.get_device(p) as dev:
                if int(dev) == -1:
                    g += rate * sign
                else:
                    kernel(sign, rate, g)
array.py 文件源码 项目:chainer-deconv 作者: germanRos 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def empty_like(x):
    if cuda.available and isinstance(x, cuda.ndarray):
        return cuda.cupy.empty_like(x)
    else:
        return numpy.empty_like(x)
test_cuda.py 文件源码 项目:chainer-deconv 作者: germanRos 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_get_dummy_device(self):
        if not cuda.available:
            self.assertIs(cuda.get_device(), cuda.DummyDevice)
test_cuda.py 文件源码 项目:chainer-deconv 作者: germanRos 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def test_to_gpu_unavailable(self):
        x = numpy.array([1])
        if not cuda.available:
            with self.assertRaises(RuntimeError):
                cuda.to_gpu(x)
test_cuda.py 文件源码 项目:chainer-deconv 作者: germanRos 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_empy_like_unavailable(self):
        x = numpy.array([1])
        if not cuda.available:
            with self.assertRaises(RuntimeError):
                cuda.empty_like(x)
weight_clip.py 文件源码 项目:GUINNESS 作者: HirokiNakahara 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __call__(self, opt):
        if cuda.available:
            kernel = cuda.elementwise(
                'T low, T high', 
                'T p', 
                'p = (p < low) ? low : (p > high) ? high : p',
                'weight_clip')

        for param in opt.target.params():
            p = param.data
            with cuda.get_device(p) as dev:
                if int(dev) == -1:
                    numpy.clip(p, self.low, self.high)
                else:
                    kernel(self.low, self.high, p)
timer.py 文件源码 项目:chainer-deepmark 作者: delta2323 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, blocking_method='non_block'):
        if not cuda.available:
            raise RuntimeError('CUDA must be available to use GPUTimer.')

        if not (blocking_method == 'non_block' or
                blocking_method == 'block_first_time' or
                blocking_method == 'block_every_time'):
            raise ValueError(
                'Invalid blocking method:{}'.format(blocking_method))
        self.blocking_method = blocking_method
        self.reset()
weight_clip.py 文件源码 项目:BinaryNetConvolution 作者: rarilurelo 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def __call__(self, opt):
        if cuda.available:
            kernel = cuda.elementwise(
                'T low, T high', 
                'T p', 
                'p = (p < low) ? low : (p > high) ? high : p',
                'weight_clip')

        for param in opt.target.params():
            p = param.data
            with cuda.get_device(p) as dev:
                if int(dev) == -1:
                    numpy.clip(p, self.low, self.high)
                else:
                    kernel(self.low, self.high, p)
gan.py 文件源码 项目:unrolled-gan 作者: musyoku 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def gpu_enabled(self):
        if cuda.available is False:
            return False
        return self._gpu
wavenet.py 文件源码 项目:wavenet 作者: musyoku 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def gpu_enabled(self):
        if cuda.available is False:
            return False
        return self._gpu
gan.py 文件源码 项目:LSGAN 作者: musyoku 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def gpu_enabled(self):
        if cuda.available is False:
            return False
        return self._gpu
adgm.py 文件源码 项目:adgm 作者: musyoku 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def gpu_enabled(self):
        if cuda.available is False:
            return False
        return self._gpu
vae_m2.py 文件源码 项目:variational-autoencoder 作者: musyoku 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def gpu(self):
        if cuda.available is False:
            return False
        return True if self.xp is cuda.cupy else False
vae_m1.py 文件源码 项目:variational-autoencoder 作者: musyoku 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def gpu(self):
        if cuda.available is False:
            return False
        return True if self.xp is cuda.cupy else False


问题


面经


文章

微信
公众号

扫码关注公众号