python_code stringlengths 0 1.02M | repo_name stringlengths 9 48 | file_path stringlengths 5 114 |
|---|---|---|
import ast
with open("../python/__init__.py", "r") as f:
tree = ast.parse(f.read())
print("\nDeviceType = int\n")
print("# These are freedom-patched into caffe2_pb2 in caffe2/proto/__init__.py")
for stmt in tree.body:
if not isinstance(stmt, ast.Assign):
continue
target = stmt.targets[0]
if no... | pytorch-master | caffe2/proto/gen_proto_typestubs_helper.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... | pytorch-master | caffe2/python/filler_test.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... | pytorch-master | caffe2/python/optimizer_test_util.py |
## @package muji
# Module caffe2.python.muji
"""muji.py does multi-gpu training for caffe2 with no need to change the c++
side code. Everything is defined on the computation graph level.
We support the following use cases:
- 2 gpus, where peer access is enabled between them.
- 4 gpus, where peer access are enabled... | pytorch-master | caffe2/python/muji.py |
import caffe2.python._import_c_extension as C
CAFFE2_NO_OPERATOR_SCHEMA = C.define_caffe2_no_operator_schema
build_options = C.get_build_options()
| pytorch-master | caffe2/python/build.py |
from future.utils import viewkeys
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... | pytorch-master | caffe2/python/data_parallel_model_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... | pytorch-master | caffe2/python/transformations_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... | pytorch-master | caffe2/python/numa_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... | pytorch-master | caffe2/python/layers_test.py |
#!/usr/bin/env python3
import string
import argparse
import numpy as np
from caffe2.python.model_helper import ModelHelper
from caffe2.python.predictor import mobile_exporter
from caffe2.python import core, workspace, brew, utils
def parse_kwarg(kwarg_str):
key, value = map(string.strip, kwarg_str.split("... | pytorch-master | caffe2/python/benchmark_generator.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 ... | pytorch-master | caffe2/python/gradient_check_test.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),... | pytorch-master | caffe2/python/attention.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
from future.utils import viewitems
def _merge_node_kwargs(a, b):
# TODO(azzolini): consistency checks
if a is N... | pytorch-master | caffe2/python/task.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... | pytorch-master | caffe2/python/convnet_benchmarks_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, ... | pytorch-master | caffe2/python/optimizer_test.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... | pytorch-master | caffe2/python/fakefp16_transform_lib.py |
## @package optimizer_context
# Module caffe2.python.optimizer_context
from caffe2.python import context
from caffe2.python.modifier_context import (
ModifierContext, UseModifierBase)
DEFAULT_OPTIM = 'DEFAULT'
class OptimizerContext(ModifierContext, context.DefaultManaged):
"""
provide context to a... | pytorch-master | caffe2/python/optimizer_context.py |
from caffe2.python import scope, core, workspace
import unittest
import threading
import time
SUCCESS_COUNT = 0
def thread_runner(idx, testobj):
global SUCCESS_COUNT
testobj.assertEquals(scope.CurrentNameScope(), "")
testobj.assertEquals(scope.CurrentDeviceScope(), None)
namescope = "namescope_... | pytorch-master | caffe2/python/scope_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()... | pytorch-master | caffe2/python/python_op_test.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... | pytorch-master | caffe2/python/hsm_util.py |
from caffe2.python.schema import (
Struct, FetchRecord, NewRecord, FeedRecord, InitEmptyRecord)
from caffe2.python import core, workspace
from caffe2.python.session import LocalSession
from caffe2.python.dataset import Dataset
from caffe2.python.pipeline import pipe
from caffe2.python.queue_util import Queue
f... | pytorch-master | caffe2/python/pipeline_test.py |
## @package memonger
# Module caffe2.python.memonger
import networkx as nx
import collections
import time
import copy
from caffe2.python import workspace, core
from caffe2.proto import caffe2_pb2
import enum
import logging
from future.utils import viewitems, viewvalues
import caffe2.python._import_c_extension as C... | pytorch-master | caffe2/python/memonger.py |
import caffe2.python.hypothesis_test_util as hu
import hypothesis.strategies as st
import numpy as np
import numpy.testing as npt
from caffe2.python import core, layer_model_instantiator, regularizer, schema, workspace
from caffe2.python.layer_test_util import LayersTestCase
from caffe2.python.optimizer import SgdOpt... | pytorch-master | caffe2/python/regularizer_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... | pytorch-master | caffe2/python/parallel_workers_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):
... | pytorch-master | caffe2/python/brew_test.py |
## @package layer_test_util
# Module caffe2.python.layer_test_util
from collections import namedtuple
from caffe2.python import (
core,
layer_model_instantiator,
layer_model_helper,
schema,
test_util,
workspace,
utils,
)
from caffe2.proto import caffe2_pb2
import numpy as np
# pyre-f... | pytorch-master | caffe2/python/layer_test_util.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.
... | pytorch-master | caffe2/python/model_device_test.py |
from caffe2.python import net_printer
from caffe2.python.checkpoint import Job
from caffe2.python.net_builder import ops
from caffe2.python.task import Task, final_output, WorkspaceType
import unittest
def example_loop():
with Task():
total = ops.Const(0)
total_large = ops.Const(0)
to... | pytorch-master | caffe2/python/net_printer_test.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... | pytorch-master | caffe2/python/crf_predict.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... | pytorch-master | caffe2/python/dataio.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... | pytorch-master | caffe2/python/utils_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):
... | pytorch-master | caffe2/python/schema_test.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(... | pytorch-master | caffe2/python/checkpoint.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
from future.utils import viewvalues
import hypothesis.strategies as st
from hypothesis import given, settings
import unittest
def has_blob(pro... | pytorch-master | caffe2/python/memonger_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... | pytorch-master | caffe2/python/transformations.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... | pytorch-master | caffe2/python/parallel_workers.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,... | pytorch-master | caffe2/python/hypothesis_test_util.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... | pytorch-master | caffe2/python/sparse_to_dense_mask_test.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... | pytorch-master | caffe2/python/crf.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... | pytorch-master | caffe2/python/operator_fp_exceptions_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... | pytorch-master | caffe2/python/control_ops_grad_test.py |
## @package recurrent
# Module caffe2.python.recurrent
from caffe2.python import core, workspace
from future.utils import viewitems, viewkeys
def recurrent_net(
net, cell_net, inputs, initial_cell_inputs,
links, timestep=None, scope=None, outputs_with_grads=(0,),
recompute_blobs_on_backwar... | pytorch-master | caffe2/python/recurrent.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... | pytorch-master | caffe2/python/sparse_to_dense_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... | pytorch-master | caffe2/python/lazy_dyndep_test.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... | pytorch-master | caffe2/python/regularizer_context.py |
import unittest
from caffe2.python import core
from hypothesis import given
import hypothesis.strategies as st
import caffe2.python.hypothesis_test_util as hu
from caffe2.python import workspace
from caffe2.python.functional import Functional
import numpy as np
@st.composite
def _tensor_splits(draw, add_axis=Fa... | pytorch-master | caffe2/python/functional_test.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 ... | pytorch-master | caffe2/python/lazy_dyndep.py |
## @package workspace
# Module caffe2.python.workspace
| pytorch-master | caffe2/python/convert.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... | pytorch-master | caffe2/python/control_ops_util.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
from future.utils import viewitems
# Used to generate names of the steps cr... | pytorch-master | caffe2/python/control.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... | pytorch-master | caffe2/python/allcompare_test.py |
## @package timeout_guard
# Module caffe2.python.timeout_guard
import contextlib
import threading
import os
import time
import signal
import logging
from future.utils import viewitems
'''
Sometimes CUDA devices can get stuck, 'deadlock'. In this case it is often
better just the kill the process automatically. Us... | pytorch-master | caffe2/python/timeout_guard.py |
# @package modifier_context
# Module caffe2.python.modifier_context
DEFAULT_MODIFIER = 'DEFAULT'
class ModifierContext(object):
"""
provide context to allow param_info to have different modifiers
"""
def __init__(self):
self._modifiers = {}
self._modifiers_list = []
def _re... | pytorch-master | caffe2/python/modifier_context.py |
import errno
import os
import shutil
import tempfile
import unittest
from collections import namedtuple
from typing import List
import caffe2.python.hypothesis_test_util as htu
import hypothesis.strategies as st
import numpy as np
import torch
from torch import Tensor
from caffe2.proto import caffe2_pb2
from caffe2.py... | pytorch-master | caffe2/python/workspace_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... | pytorch-master | caffe2/python/lengths_reducer_fused_8bit_rowwise_ops_test.py |
## @package experiment_util
# Module caffe2.python.experiment_util
import datetime
import time
import logging
import socket
import abc
from collections import OrderedDict
from future.utils import viewkeys, viewvalues
'''
Utilities for logging experiment run stats, such as accuracy
and loss over time for differen... | pytorch-master | caffe2/python/experiment_util.py |
## @package session
# Module caffe2.python.session
from caffe2.python import core, workspace
from caffe2.python.task import Cluster, Task, TaskGroup, WorkspaceType
class CompiledRunnable(object):
""" Wrapper for compiled runnable returned from session.compile() """
def __init__(self, obj, session_class)... | pytorch-master | caffe2/python/session.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... | pytorch-master | caffe2/python/record_queue.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... | pytorch-master | caffe2/python/layer_model_instantiator.py |
## @package rnn_cell
# Module caffe2.python.rnn_cell
import functools
import inspect
import logging
import numpy as np
import random
from future.utils import viewkeys
from caffe2.proto import caffe2_pb2
from caffe2.python.attention import (
apply_dot_attention,
apply_recurrent_attention,
apply_regular... | pytorch-master | caffe2/python/rnn_cell.py |
## @package _import_c_extension
# Module caffe2.python._import_c_extension
import atexit
import logging
import sys
from caffe2.python import extension_loader
# We will first try to load the gpu-enabled caffe2. If it fails, we will then
# attempt to load the cpu version. The cpu backend is the minimum required, so
# if... | pytorch-master | caffe2/python/_import_c_extension.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... | pytorch-master | caffe2/python/__init__.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... | pytorch-master | caffe2/python/parallelize_bmuf_distributed_test.py |
import functools
from caffe2.python import brew, rnn_cell
class GRUCell(rnn_cell.RNNCell):
def __init__(
self,
input_size,
hidden_size,
forget_bias, # Currently unused! Values here will be ignored.
memory_optimization,
drop_states=False,
linear_befor... | pytorch-master | caffe2/python/gru_cell.py |
"""A tool to inspect the binary size of a built binary file.
This script prints out a tree of symbols and their corresponding sizes, using
Linux's nm functionality.
Usage:
python binary_size.py -- \
--target=/path/to/your/target/binary \
[--nm_command=/path/to/your/custom/nm] \
... | pytorch-master | caffe2/python/binarysize.py |
# @package regularizer_context
# Module caffe2.python.normalizer_context
from caffe2.python import context
from caffe2.python.modifier_context import (
ModifierContext, UseModifierBase)
class NormalizerContext(ModifierContext, context.DefaultManaged):
"""
provide context to allow param_info to have d... | pytorch-master | caffe2/python/normalizer_context.py |
## @package core
# Module caffe2.python.core
from collections import namedtuple, OrderedDict, defaultdict
from past.builtins import basestring
from future.utils import viewitems, viewkeys, viewvalues
from itertools import chain
from six import binary_type, string_types, text_type
from caffe2.proto import caffe2_p... | pytorch-master | caffe2/python/core.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... | pytorch-master | caffe2/python/fused_8bit_rowwise_conversion_ops_test.py |
## @package queue_util
# Module caffe2.python.queue_util
from caffe2.python import core, dataio
from caffe2.python.task import TaskGroup
import logging
logger = logging.getLogger(__name__)
class _QueueReader(dataio.Reader):
def __init__(self, wrapper, num_dequeue_records=1):
assert wrapper.schema ... | pytorch-master | caffe2/python/queue_util.py |
## @package predictor_constants
# Module caffe2.python.predictor_constants
import caffe2.proto.predictor_consts_pb2 as predictor_consts
predictor_constants = predictor_consts.PredictorConsts()
| pytorch-master | caffe2/python/predictor_constants.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 ... | pytorch-master | caffe2/python/convnet_benchmarks.py |
## @package gradient_checker
# Module caffe2.python.gradient_checker
import os
import numpy as np
from caffe2.python import core, workspace, net_drawer
from caffe2.proto import caffe2_pb2
def getGradientForOp(op):
return core.GradientRegistry.GetGradientForOp(
op, [s + '_grad' for s in op.output])
... | pytorch-master | caffe2/python/gradient_checker.py |
import numpy as np
import copy
import time
from functools import partial, reduce
from future.utils import viewitems, viewkeys
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... | pytorch-master | caffe2/python/hypothesis_test.py |
## @package visualize
# Module caffe2.python.visualize
"""Functions that could be used to visualize Tensors.
This is adapted from the old-time iceberk package that Yangqing wrote... Oh gold
memories. Before decaf and caffe. Why iceberk? Because I was at Berkeley,
bears are vegetarian, and iceberg lettuce has layers of... | pytorch-master | caffe2/python/visualize.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... | pytorch-master | caffe2/python/checkpoint_test.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... | pytorch-master | caffe2/python/cnn.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... | pytorch-master | caffe2/python/test_util.py |
from caffe2.python import control, core, test_util, workspace
import logging
logger = logging.getLogger(__name__)
class TestControl(test_util.TestCase):
def setUp(self):
super(TestControl, self).setUp()
self.N_ = 10
self.init_net_ = core.Net("init-net")
cnt = self.init_net_.... | pytorch-master | caffe2/python/control_test.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... | pytorch-master | caffe2/python/embedding_generation_benchmark.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)... | pytorch-master | caffe2/python/normalizer_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"),
... | pytorch-master | caffe2/python/db_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(... | pytorch-master | caffe2/python/core_test.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... | pytorch-master | caffe2/python/nomnigraph_transformations.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... | pytorch-master | caffe2/python/dataset.py |
## @package text_file_reader
# Module caffe2.python.text_file_reader
from caffe2.python import core
from caffe2.python.dataio import Reader
from caffe2.python.schema import Scalar, Struct, data_type_for_dtype
class TextFileReader(Reader):
"""
Wrapper around operators for reading from text files.
"""
... | pytorch-master | caffe2/python/text_file_reader.py |
import numpy as np
import unittest
import time
from caffe2.python import workspace, model_helper
from caffe2.python import timeout_guard
import caffe2.python.data_workers as data_workers
def dummy_fetcher(fetcher_id, batch_size):
# Create random amount of values
n = np.random.randint(64) + 1
data = ... | pytorch-master | caffe2/python/data_workers_test.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... | pytorch-master | caffe2/python/mkl_test_util.py |
## @package db_file_reader
# Module caffe2.python.db_file_reader
from caffe2.python import core, scope, workspace, _import_c_extension as C
from caffe2.python.dataio import Reader
from caffe2.python.dataset import Dataset
from caffe2.python.schema import from_column_list
import os
class DBFileReader(Reader):
... | pytorch-master | caffe2/python/db_file_reader.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(... | pytorch-master | caffe2/python/nomnigraph_transformations_test.py |
from caffe2.python import core, workspace
from caffe2.proto import caffe2_pb2
from caffe2.python.onnx.workspace import Workspace
from collections import namedtuple
from six import string_types
OpSchema = workspace.C.OpSchema
def namedtupledict(typename, field_names, *args, **kwargs):
field_names_map = {n: i... | pytorch-master | caffe2/python/functional.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... | pytorch-master | caffe2/python/net_builder.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
from future.utils import viewitems
class DeviceChecker(object):
"""A device checker in Python to check consistency across mult... | pytorch-master | caffe2/python/device_checker.py |
## @package context
# Module caffe2.python.context
import inspect
import threading
import functools
class _ContextInfo(object):
def __init__(self, cls, allow_default):
self.cls = cls
self.allow_default = allow_default
self._local_stack = threading.local()
@property
def _stack(sel... | pytorch-master | caffe2/python/context.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... | pytorch-master | caffe2/python/caffe_translator_test.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... | pytorch-master | caffe2/python/caffe_translator.py |
# @package utils
# Module caffe2.python.utils
from caffe2.proto import caffe2_pb2
from future.utils import viewitems
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
from six import intege... | pytorch-master | caffe2/python/utils.py |
## @package pipeline
# Module caffe2.python.pipeline
from caffe2.python import core, queue_util
from caffe2.python.dataio import Reader, Writer
from caffe2.python.net_builder import NetBuilder, ops
from caffe2.python.schema import as_record, Field
from caffe2.python.task import Node, Task, TaskGroup
class Output... | pytorch-master | caffe2/python/pipeline.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... | pytorch-master | caffe2/python/task_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."""
... | pytorch-master | caffe2/python/muji_test.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... | pytorch-master | caffe2/python/cached_reader.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.