repo
stringlengths
1
99
file
stringlengths
13
215
code
stringlengths
12
59.2M
file_length
int64
12
59.2M
avg_line_length
float64
3.82
1.48M
max_line_length
int64
12
2.51M
extension_type
stringclasses
1 value
pytorch
pytorch-main/caffe2/python/transformations_test.py
# Copyright (c) 2016-present, Facebook, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed...
12,011
34.643917
110
py
pytorch
pytorch-main/caffe2/python/core_gradients_test.py
from hypothesis import given, settings import hypothesis.strategies as st import unittest from caffe2.proto import caffe2_pb2 from caffe2.python import core, test_util, workspace from caffe2.python.core import CreateOperator, GradientRegistry, IR import numpy as np # First, we will set up a few gradient regist...
38,019
36.60633
81
py
pytorch
pytorch-main/caffe2/python/lengths_reducer_rowwise_8bit_ops_test.py
from caffe2.python import core, workspace import caffe2.python.hypothesis_test_util as hu import numpy as np def FakeQuantization8BitsRowwise(data): min_el = np.min(data, axis=1) max_el = np.max(data, axis=1) scale = (max_el - min_el) / 255. bias = min_el inv_scale = 1. / scale data = da...
5,710
36.572368
78
py
pytorch
pytorch-main/caffe2/python/checkpoint.py
## @package checkpoint # Module caffe2.python.checkpoint import os import logging from caffe2.python import core, context from caffe2.python.net_builder import ops from caffe2.python.task import ( final_output, Node, Task, TaskGroup, TaskOutput, WorkspaceType, ) logger = logging.getLogger(...
32,047
37.426859
87
py
pytorch
pytorch-main/caffe2/python/sparse_to_dense_test.py
from caffe2.python import core, workspace from caffe2.python.test_util import TestCase import numpy as np class TestSparseToDense(TestCase): def test_sparse_to_dense(self): op = core.CreateOperator( 'SparseToDense', ['indices', 'values'], ['output']) worksp...
3,556
31.045045
75
py
pytorch
pytorch-main/caffe2/python/context.py
## @package context # Module caffe2.python.context import inspect import threading import functools class _ContextInfo: def __init__(self, cls, allow_default): self.cls = cls self.allow_default = allow_default self._local_stack = threading.local() @property def _stack(self): ...
2,817
25.336449
98
py
pytorch
pytorch-main/caffe2/python/task_test.py
import unittest from caffe2.python import task class TestTask(unittest.TestCase): def testRepr(self): cases = [ (task.Cluster(), "Cluster(nodes=[], node_kwargs={})"), (task.Node(), "Node(name=local, kwargs={})"), ( task.TaskGroup(), "Task...
870
33.84
76
py
pytorch
pytorch-main/caffe2/python/core.py
## @package core # Module caffe2.python.core from collections import namedtuple, OrderedDict, defaultdict from past.builtins import basestring from itertools import chain from caffe2.proto import caffe2_pb2 from caffe2.python import scope, utils, workspace from caffe2.python.lazy import TriggerLazyImport from caf...
118,950
37.733637
92
py
pytorch
pytorch-main/caffe2/python/convnet_benchmarks.py
## @package convnet_benchmarks # Module caffe2.python.convnet_benchmarks """ Benchmark for common convnets. Speed on Titan X, with 10 warmup steps and 10 main steps and with different versions of cudnn, are as follows (time reported below is per-batch time, forward / forward+backward): CuDNN V3 ...
20,533
27.206044
81
py
pytorch
pytorch-main/caffe2/python/parallel_workers.py
# @package parallel_workers # Module caffe2.python.parallel_workers ''' This module provides a python-land multithreaded mechanism for executing work. Basic usage is as follows: coordinator = parallel_workers.init_workers( my_worker_fun, worker_name="train" ) ... coordinator.start() Firs...
7,650
24.935593
80
py
pytorch
pytorch-main/caffe2/python/dataio.py
## @package dataio # Module caffe2.python.dataio """ Defines the base interface for reading and writing operations. Readers/Writers are objects that produce operations that read/write sequences of data. Each operation reads or writes a list of BlobReferences. Readers and Writers must be implemented such that read and...
23,391
35.779874
113
py
pytorch
pytorch-main/caffe2/python/net_builder.py
## @package net_builder # Module caffe2.python.net_builder from caffe2.python import core, context from caffe2.python.task import Task, TaskGroup from caffe2.python.control_ops_util import add_if_op, add_while_op class NetBuilder(context.Managed): """ Scope-driven mechanism for building nets, loops and c...
27,655
36.172043
82
py
pytorch
pytorch-main/caffe2/python/clean_workspace_test.py
import unittest from caffe2.python import workspace # This test is extracted out from workspace_test.py because it relies on the pristine # state of the initial workspace. When tests are run in different orders, this test may # become flaky because of global state modifications impacting what the root folder is # af...
680
41.5625
87
py
pytorch
pytorch-main/caffe2/python/caffe_translator.py
## @package caffe_translator # Module caffe2.python.caffe_translator import argparse import copy import logging import re import numpy as np # noqa from caffe2.proto import caffe2_pb2, caffe2_legacy_pb2 from caffe.proto import caffe_pb2 from caffe2.python import core, utils, workspace from google.protobuf import tex...
35,231
36.560768
91
py
pytorch
pytorch-main/caffe2/python/ideep_test_util.py
## @package ideep_test_util # Module caffe2.python.ideep_test_util """ The IDEEP test utils is a small addition on top of the hypothesis test utils under caffe2/python, which allows one to more easily test IDEEP related operators. """ import hypothesis.strategies as st from caffe2.proto import caffe2_pb2 from ca...
998
23.975
92
py
pytorch
pytorch-main/caffe2/python/layer_parameter_sharing_test.py
from caffe2.python import core, scope from caffe2.python.modeling.parameter_sharing import ( ParameterSharing, ) from caffe2.python.optimizer import AdagradOptimizer, AdamOptimizer from caffe2.python.layer_test_util import LayersTestCase class ParameterSharingTest(LayersTestCase): def test_layer_paramet...
9,132
38.197425
86
py
pytorch
pytorch-main/caffe2/python/allcompare_test.py
#!/usr/bin/env python3 from hypothesis import given, settings import hypothesis.strategies as st from multiprocessing import Process import numpy as np import tempfile import shutil import caffe2.python.hypothesis_test_util as hu op_engine = 'GLOO' class TemporaryDirectory: def __enter__(self): s...
2,255
24.636364
79
py
pytorch
pytorch-main/caffe2/python/context_test.py
from caffe2.python import context, test_util from threading import Thread class MyContext(context.Managed): pass class DefaultMyContext(context.DefaultManaged): pass class ChildMyContext(MyContext): pass class TestContext(test_util.TestCase): def use_my_context(self): try: ...
1,792
25.367647
75
py
pytorch
pytorch-main/caffe2/python/sparse_to_dense_mask_test.py
from caffe2.python import core, workspace from caffe2.python.test_util import TestCase import numpy as np class TestSparseToDenseMask(TestCase): def test_sparse_to_dense_mask_float(self): op = core.CreateOperator( 'SparseToDenseMask', ['indices', 'values', 'default', 'lengths...
6,565
40.556962
77
py
pytorch
pytorch-main/caffe2/python/db_test.py
from caffe2.python import workspace import os import tempfile import unittest class TestDB(unittest.TestCase): def setUp(self): handle, self.file_name = tempfile.mkstemp() os.close(handle) self.data = [ ( "key{}".format(i).encode("ascii"), ...
1,110
22.638298
61
py
pytorch
pytorch-main/caffe2/python/nomnigraph_test.py
from caffe2.python import core, test_util from caffe2.proto import caffe2_pb2 import caffe2.python.nomnigraph as ng from hypothesis import given import hypothesis.strategies as st import random class TestBindings(test_util.TestCase): def test_simple(self): nn = ng.NNModule() dfg = nn.dataFlo...
15,427
33.747748
81
py
pytorch
pytorch-main/caffe2/python/regularizer_context.py
# @package regularizer_context # Module caffe2.python.regularizer_context from caffe2.python import context from caffe2.python.modifier_context import ( ModifierContext, UseModifierBase) class RegularizerContext(ModifierContext, context.DefaultManaged): """ provide context to allow param_info to have...
1,013
25.684211
70
py
pytorch
pytorch-main/caffe2/python/hsm_util.py
## @package hsm_util # Module caffe2.python.hsm_util from caffe2.proto import hsm_pb2 ''' Hierarchical softmax utility methods that can be used to: 1) create TreeProto structure given list of word_ids or NodeProtos 2) create HierarchyProto structure using the user-inputted TreeProto ''' def create_n...
2,259
30.830986
78
py
pytorch
pytorch-main/caffe2/python/test_util.py
## @package test_util # Module caffe2.python.test_util import numpy as np from caffe2.python import core, workspace import os import pathlib import shutil import tempfile import unittest from typing import Any, Callable, Tuple, Type from types import TracebackType def rand_array(*dims): # np.random.rand() re...
3,524
29.387931
85
py
pytorch
pytorch-main/caffe2/python/crf_viterbi_test.py
from caffe2.python import workspace, crf from caffe2.python.cnn import CNNModelHelper from caffe2.python.crf_predict import crf_update_predictions from caffe2.python.test_util import TestCase import hypothesis.strategies as st from hypothesis import given, settings import numpy as np class TestCrfDecode(TestCase...
1,663
34.404255
77
py
pytorch
pytorch-main/caffe2/python/normalizer.py
# @package optimizer # Module caffe2.python.normalizer class Normalizer: def __init__(self): pass """ Adds normalization to train_net for given parameter. Its factor ahead of regularization is given when initialization. The param should be a BlobReference. """ def __call__(self, ...
1,361
29.266667
124
py
pytorch
pytorch-main/caffe2/python/model_helper_test.py
"""unittest for ModelHelper class""" import unittest from caffe2.python import brew, model_helper class ModelHelperTest(unittest.TestCase): def test_get_complete_net_type(self): model = model_helper.ModelHelper("test_orig") brew.conv( model, "input", "conv",...
2,336
32.385714
87
py
pytorch
pytorch-main/caffe2/python/crf_predict.py
import numpy as np from caffe2.python.crf import CRFWithLoss def crf_update_predictions(model, crf_with_loss, classes): return apply_crf( model.param_init_net, model.net, crf_with_loss.transitions, classes, crf_with_loss.num_classes, ) def apply_crf(init_net, net, t...
1,159
33.117647
77
py
pytorch
pytorch-main/caffe2/python/caffe_translator_test.py
# This a large test that goes through the translation of the bvlc caffenet # model, runs an example through the whole model, and verifies numerically # that all the results look right. In default, it is disabled unless you # explicitly want to run it. from google.protobuf import text_format import numpy as np import o...
3,553
38.054945
81
py
pytorch
pytorch-main/caffe2/python/task.py
## @package task # Module caffe2.python.task from caffe2.python import core, context from caffe2.python.schema import Field, from_blob_list from collections import defaultdict from copy import copy def _merge_node_kwargs(a, b): # TODO(azzolini): consistency checks if a is None: return b if b is N...
24,181
33.894661
81
py
pytorch
pytorch-main/caffe2/python/checkpoint_test.py
from caffe2.python.schema import Struct, ConstRecord from caffe2.python import core, workspace, model_helper from caffe2.python.session import LocalSession from caffe2.python.dataset import Dataset from caffe2.python.pipeline import pipe from caffe2.python.checkpoint import ( CheckpointManager, MultiNodeCheckp...
13,393
38.510324
88
py
pytorch
pytorch-main/caffe2/python/device_checker.py
## @package device_checker # Module caffe2.python.device_checker import numpy as np import copy from caffe2.python import workspace from caffe2.python.core import InferOpBlobDevicesAsDict class DeviceChecker: """A device checker in Python to check consistency across multiple devices. This is not the most eff...
5,111
41.6
81
py
pytorch
pytorch-main/caffe2/python/cnn.py
## @package cnn # Module caffe2.python.cnn from caffe2.python import brew, workspace from caffe2.python.model_helper import ModelHelper from caffe2.proto import caffe2_pb2 import logging class CNNModelHelper(ModelHelper): """A helper model so we can write CNN models more easily, without having to manuall...
7,606
30.564315
80
py
pytorch
pytorch-main/caffe2/python/parallelize_bmuf_distributed_test.py
from multiprocessing import Process, Manager import numpy as np import unittest import tempfile import shutil import logging from hypothesis import given, settings import hypothesis.strategies as st from caffe2.python import workspace log = logging.getLogger("parallelize_bmuf_distributed_test") log.setLevel(log...
9,908
32.589831
86
py
pytorch
pytorch-main/caffe2/python/observer_test.py
import numpy as np import unittest from hypothesis import given, settings import hypothesis.strategies as st from caffe2.python import brew, core, model_helper, rnn_cell import caffe2.python.workspace as ws class TestObservers(unittest.TestCase): def setUp(self): core.GlobalInit(["python", "caffe2"]...
5,316
33.303226
88
py
pytorch
pytorch-main/caffe2/python/brew.py
## @package model_helper_api # Module caffe2.python.model_helper_api import sys import copy import inspect from past.builtins import basestring from caffe2.python.model_helper import ModelHelper # flake8: noqa from caffe2.python.helpers.algebra import * from caffe2.python.helpers.arg_scope import * from caffe2.py...
4,762
33.021429
89
py
pytorch
pytorch-main/caffe2/python/scope.py
## @package scope # Module caffe2.python.scope import contextlib import threading from past.builtins import basestring from caffe2.proto import caffe2_pb2 # The name scope and device scope when creating a new operator. _NAMESCOPE_SEPARATOR = '/' _threadlocal_scope = threading.local() def CurrentNameScope(): ...
3,623
28.463415
83
py
pytorch
pytorch-main/caffe2/python/operator_fp_exceptions_test.py
from caffe2.python import core, workspace from caffe2.python.test_util import TestCase import numpy as np import unittest def setThrowIfFpExceptions(enabled): core.GlobalInit(["caffe2", "--caffe2_operator_throw_if_fp_exceptions=%d" % (1 if enabled else 0)]) class OperatorFPExceptionsTest(TestCase): def...
1,247
29.439024
102
py
pytorch
pytorch-main/caffe2/python/control_ops_util.py
## @package control_ops_util # Module caffe2.python.control_ops_util from caffe2.python import core def get_external_blob_names(net, lexical_scope): """ Returns a set of blobs a given net depends on and a set of output blobs that are written by the net Inputs: net - net to return input/ou...
10,863
40.151515
88
py
pytorch
pytorch-main/caffe2/python/control_ops_grad_test.py
import unittest from caffe2.python import core, test_util, workspace from caffe2.python.control_ops_grad import disambiguate_grad_if_op_output from caffe2.python.model_helper import ModelHelper import numpy as np class TestControl(test_util.TestCase): def test_disambiguate_grad_if_op_output(self): wo...
1,752
34.06
79
py
pytorch
pytorch-main/caffe2/python/record_queue.py
## @package record_queue # Module caffe2.python.record_queue """ Implementation of a queue wrapper. """ from caffe2.python import core from caffe2.python.dataio import Reader, Writer from caffe2.python.schema import ( Struct, Field, from_column_list) class _QueueReader(Reader): def __init__(self, blobs_q...
4,427
36.210084
80
py
pytorch
pytorch-main/caffe2/python/lengths_reducer_fused_8bit_rowwise_ops_test.py
import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, workspace from hypothesis import given def compare_rowwise(emb_orig, emb_reconstructed, fp16): # there is an absolute error introduced per row through int8 quantization # and...
7,575
36.320197
87
py
pytorch
pytorch-main/caffe2/python/tt_core.py
## @package tt_core # Module caffe2.python.tt_core import numpy as np """ The following methods are various utility methods for using the Tensor-Train decomposition, or TT-decomposition introduced by I. V. Oseledets (2011) in his paper (http://epubs.siam.org/doi/abs/10.1137/090752286). Broadly speaking, these met...
9,349
37.636364
80
py
pytorch
pytorch-main/caffe2/python/rnn_cell.py
## @package rnn_cell # Module caffe2.python.rnn_cell import functools import inspect import logging import numpy as np import random from caffe2.proto import caffe2_pb2 from caffe2.python.attention import ( apply_dot_attention, apply_recurrent_attention, apply_regular_attention, apply_soft_coverag...
67,985
33.353714
83
py
pytorch
pytorch-main/caffe2/python/workspace.py
## @package workspace # Module caffe2.python.workspace import collections import contextlib from google.protobuf.message import Message from multiprocessing import Process import os from collections import defaultdict import logging import numpy as np from past.builtins import basestring import shutil import socket...
25,352
31.33801
90
py
pytorch
pytorch-main/caffe2/python/functional.py
from caffe2.python import core, workspace from caffe2.proto import caffe2_pb2 from caffe2.python.onnx.workspace import Workspace from collections import namedtuple OpSchema = workspace.C.OpSchema def namedtupledict(typename, field_names, *args, **kwargs): field_names_map = {n: i for i, n in enumerate(field_...
4,369
37.333333
88
py
pytorch
pytorch-main/caffe2/python/numa_benchmark.py
from caffe2.python import core, workspace from caffe2.proto import caffe2_pb2 import time SHAPE_LEN = 4096 NUM_ITER = 1000 GB = 1024 * 1024 * 1024 NUM_REPLICAS = 48 def build_net(net_name, cross_socket): init_net = core.Net(net_name + "_init") init_net.Proto().type = "async_scheduling" numa_device_op...
2,230
30.871429
81
py
pytorch
pytorch-main/caffe2/python/hypothesis_test_util.py
## @package hypothesis_test_util # Module caffe2.python.hypothesis_test_util """ The Hypothesis library uses *property-based testing* to check invariants about the code under test under a variety of random inputs. The key idea here is to express properties of the code under test (e.g. that it passes a gradient check,...
26,853
34.710106
99
py
pytorch
pytorch-main/caffe2/python/utils.py
# @package utils # Module caffe2.python.utils from caffe2.proto import caffe2_pb2 from google.protobuf.message import DecodeError, Message from google.protobuf import text_format import sys import collections import copy import functools import numpy as np OPTIMIZER_ITERATION_NAME = "optimizer_iteration" OPTIMIZ...
14,061
31.702326
110
py
pytorch
pytorch-main/caffe2/python/memonger_test.py
import numpy as np from caffe2.python import workspace, memonger, core, model_helper, brew from caffe2.proto import caffe2_pb2 import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st from hypothesis import given, settings import unittest def has_blob(proto, needle): for op in proto.op:...
36,858
42.775534
87
py
pytorch
pytorch-main/caffe2/python/transformations.py
# Copyright (c) 2016-present, Facebook, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed...
1,824
29.932203
87
py
pytorch
pytorch-main/caffe2/python/dataset.py
## @package dataset # Module caffe2.python.dataset """ Implementation of an in-memory dataset with structured schema. Use this to store and iterate through datasets with complex schema that fit in memory. Iterating through entries of this dataset is very fast since the dataset is stored as a set of native Caffe2 tens...
12,878
36.330435
79
py
pytorch
pytorch-main/caffe2/python/nomnigraph_transformations_test.py
from caffe2.python import core, workspace from caffe2.python import test_util as tu import caffe2.python.nomnigraph as ng from caffe2.python.nomnigraph_transformations import transpose_network import numpy as np from hypothesis import given import hypothesis.strategies as st class TestNomnigraphTransformations(...
5,767
38.77931
88
py
pytorch
pytorch-main/caffe2/python/layer_model_instantiator.py
## @package layer_model_instantiator # Module caffe2.python.layer_model_instantiator from caffe2.python import core, schema from caffe2.python.layers.layers import InstantiationContext from caffe2.python.layers.tags import Tags def _filter_layers(layers, include_tags): if include_tags is None: return...
3,935
33.526316
81
py
pytorch
pytorch-main/caffe2/python/normalizer_test.py
from caffe2.python.normalizer_context import UseNormalizer, NormalizerContext from caffe2.python.normalizer import BatchNormalizer from caffe2.python.layer_test_util import LayersTestCase class TestNormalizerContext(LayersTestCase): def test_normalizer_context(self): bn = BatchNormalizer(momentum=0.1)...
486
29.4375
77
py
pytorch
pytorch-main/caffe2/python/convert_test.py
from caffe2.python import workspace import unittest class TestOperator(unittest.TestCase): def setUp(self): workspace.ResetWorkspace() if __name__ == '__main__': unittest.main()
201
12.466667
38
py
pytorch
pytorch-main/caffe2/python/muji_test.py
import numpy as np import unittest from caffe2.python import core, workspace, muji, test_util @unittest.skipIf(not workspace.has_gpu_support, "no gpu") class TestMuji(test_util.TestCase): def RunningAllreduceWithGPUs(self, gpu_ids, allreduce_function): """A base function to test different scenarios.""" ...
3,058
35.855422
91
py
pytorch
pytorch-main/caffe2/python/numa_test.py
from caffe2.python import core, workspace from caffe2.proto import caffe2_pb2 from caffe2.python.test_util import TestCase import unittest core.GlobalInit(["caffe2", "--caffe2_cpu_numa_enabled=1"]) def build_test_net(net_name): net = core.Net(net_name) net.Proto().type = "async_scheduling" numa_devic...
1,663
29.814815
74
py
pytorch
pytorch-main/caffe2/python/lazy_dyndep.py
## @package lazy_dyndep # Module caffe2.python.lazy_dyndep import os from caffe2.python import dyndep, lazy def RegisterOpsLibrary(name): """Registers a dynamic library that contains custom operators into Caffe2. Since Caffe2 uses static variable registration, you can optionally load a separate .so ...
2,562
29.152941
83
py
pytorch
pytorch-main/caffe2/python/control.py
## @package control # Module caffe2.python.control """ Implement functions for controlling execution of nets and steps, including Do DoParallel For-loop While-loop Do-While-loop Switch If """ from caffe2.python import core # Used to generate names of the steps created by the control functions. # I...
19,271
32.516522
80
py
pytorch
pytorch-main/caffe2/python/hip_test_util.py
## @package hip_test_util # Module caffe2.python.hip_test_util """ The HIP test utils is a small addition on top of the hypothesis test utils under caffe2/python, which allows one to more easily test HIP/ROCm related operators. """ from caffe2.proto import caffe2_pb2 def run_in_hip(gc, dc): return (gc.device...
405
20.368421
74
py
pytorch
pytorch-main/caffe2/python/embedding_generation_benchmark.py
## @package embedding_generation_benchmark # Module caffe2.python.embedding_generation_benchmark from caffe2.proto import caffe2_pb2 from caffe2.python import workspace, core, utils, model_helper import argparse import numpy as np import time import logging logging.basicConfig() log = logging.getLogger("embeddi...
5,256
25.685279
75
py
pytorch
pytorch-main/caffe2/python/experiment_util.py
## @package experiment_util # Module caffe2.python.experiment_util import datetime import time import logging import socket import abc from collections import OrderedDict ''' Utilities for logging experiment run stats, such as accuracy and loss over time for different runs. Runtime arguments are stored in the lo...
3,562
30.254386
74
py
pytorch
pytorch-main/caffe2/python/mkl_test_util.py
## @package mkl_test_util # Module caffe2.python.mkl_test_util """ The MKL test utils is a small addition on top of the hypothesis test utils under caffe2/python, which allows one to more easily test MKL related operators. """ import hypothesis.strategies as st from caffe2.proto import caffe2_pb2 from caffe2.pyt...
1,142
24.4
86
py
pytorch
pytorch-main/caffe2/python/fakefp16_transform_lib.py
#!/usr/bin/env python3 import caffe2.python._import_c_extension as C from caffe2.proto.caffe2_pb2 import NetDef def fakeFp16FuseOps(net : NetDef) -> NetDef: net_str = net.SerializeToString() out_str = C.fakeFp16FuseOps(net_str) out_net = NetDef() out_net.ParseFromString(out_str) return out_ne...
322
18
45
py
pytorch
pytorch-main/caffe2/python/predictor_constants.py
## @package predictor_constants # Module caffe2.python.predictor_constants import caffe2.proto.predictor_consts_pb2 as predictor_consts predictor_constants = predictor_consts.PredictorConsts()
198
18.9
60
py
pytorch
pytorch-main/caffe2/python/python_op_test.py
from caffe2.python import core, workspace from caffe2.python.core import CreatePythonOperator import caffe2.python.hypothesis_test_util as hu from hypothesis import given, settings import hypothesis.strategies as st import numpy as np class CustomError(Exception): pass def SubFunctionThatThrowsCustomError()...
9,169
36.276423
97
py
pytorch
pytorch-main/caffe2/python/regularizer.py
# @package optimizer # Module caffe2.python.regularizer from caffe2.python import core, utils import numpy as np class RegularizationBy: AFTER_OPTIMIZER = "after_optimizer" ON_LOSS = "on_loss" class Regularizer: def __init__(self): self.kEpsilon = 1e-9 """ Adds regularization to train...
20,837
36.887273
133
py
pytorch
pytorch-main/caffe2/python/recurrent.py
## @package recurrent # Module caffe2.python.recurrent from caffe2.python import core, workspace def recurrent_net( net, cell_net, inputs, initial_cell_inputs, links, timestep=None, scope=None, outputs_with_grads=(0,), recompute_blobs_on_backward=None, forward_only=False, ): ''' ne...
13,243
38.771772
80
py
pytorch
pytorch-main/caffe2/python/tt_core_test.py
import numpy as np import unittest from caffe2.python import core, workspace, tt_core import caffe2.python.hypothesis_test_util as hu class TestTTSVD(hu.HypothesisTestCase): def test_full_tt_svd(self): size = 256 np.random.seed(1234) X = np.expand_dims( np.random.rand(siz...
2,516
29.325301
79
py
pytorch
pytorch-main/caffe2/python/extension_loader.py
## @package extension_loader # Module caffe2.python.extension_loader import contextlib import ctypes import sys _set_global_flags = ( hasattr(sys, 'getdlopenflags') and hasattr(sys, 'setdlopenflags')) @contextlib.contextmanager def DlopenGuard(extra_flags=ctypes.RTLD_GLOBAL): if _set_global_flags: ...
744
23.833333
80
py
pytorch
pytorch-main/caffe2/python/data_parallel_model.py
## @package data_parallel_model # Module caffe2.python.data_parallel_model from collections import OrderedDict import logging import copy from multiprocessing import cpu_count from caffe2.python import \ model_helper, dyndep, scope, workspace, core, memonger, utils from caffe2.proto import caffe2_pb2 import ...
82,978
36.344284
107
py
pytorch
pytorch-main/caffe2/python/model_helper.py
## @package model_helper # Module caffe2.python.model_helper from caffe2.python import core, scope, workspace from caffe2.python.helpers.db_input import db_input from caffe2.python.modeling import parameter_info from caffe2.python.modeling.parameter_sharing import ( parameter_sharing_context, ) from caffe2.pyt...
23,457
35.256569
86
py
pytorch
pytorch-main/caffe2/python/lazy_dyndep_test.py
#!/usr/bin/env python3 from hypothesis import given, settings import hypothesis.strategies as st from multiprocessing import Process import numpy as np import tempfile import shutil import caffe2.python.hypothesis_test_util as hu import unittest op_engine = 'GLOO' class TemporaryDirectory: def __enter__(s...
3,914
28.216418
96
py
pytorch
pytorch-main/caffe2/python/crf.py
## @package crf # Module caffe2.python.crf import numpy as np from caffe2.python import brew, core, model_helper, recurrent """ Due to a limitation in ReccurentNetworkOp, this layer only supports batch_size=1 In order to support batch_size > 1, we will have to implement the CRFUnit and its gradient in C++ and handl...
13,242
41.175159
86
py
pytorch
pytorch-main/caffe2/python/schema_test.py
from caffe2.python import core, schema import numpy as np import unittest import pickle import random class TestField(unittest.TestCase): def testInitShouldSetEmptyParent(self): f = schema.Field([]) self.assertTupleEqual(f._parent, (None, 0)) def testInitShouldSetFieldOffsets(self): ...
15,725
32.317797
81
py
pytorch
pytorch-main/caffe2/python/nomnigraph_transformations.py
from collections import defaultdict import caffe2.python.nomnigraph as ng from caffe2.python import core, utils def transpose_network(nn): """ Convert all Convolutions operators which are in the NCHW order to NHWC order and also transform their inputs and outputs so that the rest of the graph is no...
3,787
41.561798
79
py
pytorch
pytorch-main/caffe2/python/timeout_guard.py
## @package timeout_guard # Module caffe2.python.timeout_guard import contextlib import threading import os import time import signal import logging ''' Sometimes CUDA devices can get stuck, 'deadlock'. In this case it is often better just the kill the process automatically. Use this guard to set a maximum times...
4,013
34.210526
96
py
pytorch
pytorch-main/caffe2/python/gradient_check_test.py
# TODO(jiayq): as more and more tests are moving to hypothesis test, we # can gradually remove this test script. DO NOT ADD MORE TESTS TO THIS # FILE. import numpy as np from caffe2.python import ( brew, core, device_checker, gradient_checker, model_helper, test_util, workspace, ) from ...
20,729
36.150538
84
py
pytorch
pytorch-main/caffe2/python/session.py
## @package session # Module caffe2.python.session from caffe2.python import core, workspace from caffe2.python.task import Cluster, Task, TaskGroup, WorkspaceType class CompiledRunnable: """ Wrapper for compiled runnable returned from session.compile() """ def __init__(self, obj, session_class): ...
7,626
34.640187
88
py
pytorch
pytorch-main/caffe2/python/data_parallel_model_test.py
from multiprocessing import Process, Queue import numpy as np import os import shutil import tempfile import unittest import time from mock import Mock from hypothesis import assume, given, settings import hypothesis.strategies as st from caffe2.proto import caffe2_pb2 from caffe2.python import brew, core, cnn, da...
56,108
38.292017
174
py
pytorch
pytorch-main/caffe2/python/net_drawer.py
## @package net_drawer # Module caffe2.python.net_drawer import argparse import json import logging from collections import defaultdict from caffe2.python import utils logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) try: import pydot except ImportError: logger.info( 'Cannot impo...
14,226
33.531553
80
py
pytorch
pytorch-main/caffe2/python/model_device_test.py
import numpy as np import unittest from caffe2.proto import caffe2_pb2 from caffe2.python import ( workspace, device_checker, test_util, model_helper, brew, ) class TestMiniAlexNet(test_util.TestCase): def _MiniAlexNetNoDropout(self, order): # First, AlexNet using the cnn wrapper. ...
4,777
30.228758
80
py
pytorch
pytorch-main/caffe2/python/convnet_benchmarks_test.py
import unittest from caffe2.python import convnet_benchmarks as cb from caffe2.python import test_util, workspace # TODO: investigate why this randomly core dump in ROCM CI @unittest.skipIf(not workspace.has_cuda_support, "no cuda gpu") class TestConvnetBenchmarks(test_util.TestCase): def testConvnetBenchmarks(se...
839
34
76
py
pytorch
pytorch-main/caffe2/python/optimizer_test.py
from caffe2.proto import caffe2_pb2 import caffe2.python.optimizer as optimizer from caffe2.python.optimizer import ( build_sgd, build_multi_precision_sgd, build_ftrl, build_gftrl, build_wngrad, build_adagrad, build_adadelta, build_adam, build_yellowfin, build_rms_prop, build_storm, build_decay_adagrad, ...
31,622
39.64653
120
py
pytorch
pytorch-main/caffe2/python/brew_test.py
from caffe2.python import brew, core, scope, workspace from caffe2.python.modeling.parameter_info import ParameterTags from caffe2.python.model_helper import ModelHelper from caffe2.python.cnn import CNNModelHelper import unittest import numpy as np class BrewTest(unittest.TestCase): def setUp(self): ...
11,739
34.683891
83
py
pytorch
pytorch-main/caffe2/python/layers_test.py
import hypothesis.strategies as st import numpy as np import numpy.testing as npt from hypothesis import given, settings import caffe2.python.hypothesis_test_util as hu from caffe2.python import ( layer_model_instantiator, core, schema, workspace, ) from caffe2.python.layers.layers import ( A...
92,930
35.921335
122
py
pytorch
pytorch-main/caffe2/python/filler_test.py
from caffe2.python import core, test_util, workspace class TestFiller(test_util.TestCase): def test_filler(self): net = core.Net("test_filler") net.Concat(["X0", "X1", "X2"], ["concat_out", "split_info"]) self.assertFalse(workspace.HasBlob("X0")) input_dim = (30, 20) wo...
748
34.666667
114
py
pytorch
pytorch-main/caffe2/python/data_workers.py
## @package data_workers # Module caffe2.python.data_workers ''' This module provides a python-land multithreaded data input mechanism for Caffe2 nets. Basic usage is as follows: coordinator = data_workers.init_data_input_workers( net, ["data", "label"], my_fetch_fun, batch_size=32, ...
15,941
33.506494
96
py
pytorch
pytorch-main/caffe2/python/convert.py
## @package workspace # Module caffe2.python.workspace
55
17.666667
32
py
pytorch
pytorch-main/caffe2/python/__init__.py
import os import sys import warnings try: from caffe2.proto import caffe2_pb2 except ImportError: warnings.warn('Caffe2 support is not enabled in this PyTorch build. ' 'Please enable Caffe2 by building PyTorch from source with `BUILD_CAFFE2=1` flag.') raise # TODO: refactor & remove the...
3,754
41.670455
108
py
pytorch
pytorch-main/caffe2/python/core_test.py
from inspect import currentframe, getframeinfo import unittest import numpy as np from caffe2.proto import caffe2_pb2 from caffe2.python import core, workspace, schema, test_util from caffe2.python.task import Node, Task class TestScopes(test_util.TestCase): def testBlobReferenceIsIndependentFromNameScope(...
47,678
36.690909
93
py
pytorch
pytorch-main/caffe2/python/fused_8bit_rowwise_conversion_ops_test.py
from caffe2.python import core, workspace import caffe2.python.hypothesis_test_util as hu import numpy as np import struct from hypothesis import given # Eigen/Python round 0.5 away from 0, Numpy rounds to even round_to_nearest = np.vectorize(round) def bytes_to_floats(byte_matrix): floats = np.empty([np.s...
3,991
36.308411
93
py
pytorch
pytorch-main/caffe2/python/cached_reader.py
## @package cached_reader # Module caffe2.python.cached_reader import os from caffe2.python import core from caffe2.python.db_file_reader import DBFileReader from caffe2.python.pipeline import pipe from caffe2.python.task import Cluster, TaskGroup class CachedReader(DBFileReader): default_name_suffix = 'ca...
4,376
31.664179
82
py
pytorch
pytorch-main/caffe2/python/hypothesis_test.py
import numpy as np import copy import time from functools import partial, reduce from hypothesis import assume, given, settings, HealthCheck import hypothesis.strategies as st import unittest import threading from caffe2.python import core, workspace, tt_core, dyndep import caffe2.python.hypothesis_test_util as hu fro...
105,855
36.792217
101
py
pytorch
pytorch-main/caffe2/python/parallel_workers_test.py
import unittest from caffe2.python import workspace, core import caffe2.python.parallel_workers as parallel_workers def create_queue(): queue = 'queue' workspace.RunOperatorOnce( core.CreateOperator( "CreateBlobsQueue", [], [queue], num_blobs=1, capacity=1000 ) ) # T...
3,501
28.183333
90
py
pytorch
pytorch-main/caffe2/python/utils_test.py
from caffe2.python import core, utils, test_util import numpy as np class TestUtils(test_util.TestCase): def testArgsToDict(self): args = [utils.MakeArgument("int1", 3), utils.MakeArgument("float1", 4.0), utils.MakeArgument("string1", "foo"), utils.Mak...
1,399
33.146341
76
py
pytorch
pytorch-main/caffe2/python/optimizer_test_util.py
## @package optimizer_test_util # Module caffe2.python.optimizer_test_util import unittest import numpy as np from caffe2.python import brew, core, workspace, cnn, optimizer from caffe2.python.modeling.initializers import ( Initializer, PseudoFP16Initializer) from caffe2.python.model_helper import ModelHelper...
9,171
37.537815
80
py
pytorch
pytorch-main/caffe2/python/net_printer.py
## @package net_printer # Module caffe2.python.net_printer from caffe2.proto.caffe2_pb2 import OperatorDef, NetDef from caffe2.python.checkpoint import Job from caffe2.python.core import Net, ExecutionStep, Plan from caffe2.python.task import Task, TaskGroup, WorkspaceType, TaskOutput from collections import defau...
12,689
28.858824
80
py
pytorch
pytorch-main/caffe2/python/attention.py
## @package attention # Module caffe2.python.attention from caffe2.python import brew class AttentionType: Regular, Recurrent, Dot, SoftCoverage = tuple(range(4)) def s(scope, name): # We have to manually scope due to our internal/external blob # relationships. return "{}/{}".format(str(scope),...
12,359
28.082353
78
py