/
usr
/
local
/
lib64
/
python3.6
/
site-packages
/
torch
/
include
/
caffe2
/
core
/
/usr/local/lib64/python3.6/site-packages/torch/include/caffe2/core
mkdir
upload
Name
Size
Mode
Actions
allocator.h
136
0644
edit
dl
rm
blob.h
4168
0644
edit
dl
rm
blob_serialization.h
10791
0644
edit
dl
rm
blob_serializer_base.h
3905
0644
edit
dl
rm
blob_stats.h
1127
0644
edit
dl
rm
common.h
4329
0644
edit
dl
rm
common_cudnn.h
9893
0644
edit
dl
rm
common_gpu.h
21414
0644
edit
dl
rm
common_omp.h
156
0644
edit
dl
rm
context.h
6174
0644
edit
dl
rm
context_base.h
4382
0644
edit
dl
rm
context_gpu.h
11014
0644
edit
dl
rm
cudnn_wrappers.h
6956
0644
edit
dl
rm
db.h
9352
0644
edit
dl
rm
distributions_stubs.h
2161
0644
edit
dl
rm
event.h
12420
0644
edit
dl
rm
event_cpu.h
1192
0644
edit
dl
rm
export_c10_op_to_caffe2.h
9487
0644
edit
dl
rm
export_caffe2_op_to_c10.h
11101
0644
edit
dl
rm
flags.h
74
0644
edit
dl
rm
graph.h
5258
0644
edit
dl
rm
init.h
6496
0644
edit
dl
rm
logging.h
75
0644
edit
dl
rm
macros.h
3426
0644
edit
dl
rm
memonger.h
817
0644
edit
dl
rm
module.h
2473
0644
edit
dl
rm
net.h
4634
0644
edit
dl
rm
net_async_base.h
7397
0644
edit
dl
rm
net_async_scheduling.h
993
0644
edit
dl
rm
net_async_task.h
833
0644
edit
dl
rm
net_async_task_future.h
1925
0644
edit
dl
rm
net_async_task_graph.h
2253
0644
edit
dl
rm
net_async_tracing.h
5093
0644
edit
dl
rm
net_dag_utils.h
2146
0644
edit
dl
rm
net_parallel.h
2144
0644
edit
dl
rm
net_simple.h
2606
0644
edit
dl
rm
net_simple_refcount.h
2097
0644
edit
dl
rm
numa.h
72
0644
edit
dl
rm
observer.h
3809
0644
edit
dl
rm
operator.h
58872
0644
edit
dl
rm
operator_gradient.h
10222
0644
edit
dl
rm
operator_schema.h
18477
0644
edit
dl
rm
plan_executor.h
219
0644
edit
dl
rm
prof_dag_counters.h
2751
0644
edit
dl
rm
qtensor.h
6615
0644
edit
dl
rm
qtensor_serialization.h
2624
0644
edit
dl
rm
scope_guard.h
4675
0644
edit
dl
rm
static_tracepoint.h
398
0644
edit
dl
rm
static_tracepoint_elfx86.h
5555
0644
edit
dl
rm
stats.h
10365
0644
edit
dl
rm
storage.h
733
0644
edit
dl
rm
tensor.h
18668
0644
edit
dl
rm
tensor_impl.h
351
0644
edit
dl
rm
tensor_int8.h
450
0644
edit
dl
rm
test_utils.h
6285
0644
edit
dl
rm
timer.h
1218
0644
edit
dl
rm
transform.h
5741
0644
edit
dl
rm
types.h
2248
0644
edit
dl
rm
workspace.h
11305
0644
edit
dl
rm
Edit:
/usr/local/lib64/python3.6/site-packages/torch/include/caffe2/core/transform.h
(5741B)
#pragma once #include "caffe2/core/common.h" #include "caffe2/core/graph.h" #include "caffe2/core/workspace.h" #include "caffe2/proto/caffe2_pb.h" #include "caffe2/utils/proto_utils.h" namespace caffe2 { /** * The Transform Base Object * * A Transform is an operation which manipulates a Caffe2 NetDef. * You can consider it as a function: Transform.ApplyTo(NetDef) -> NetDef * * A Transform Operation does 4 things: * 1) Creates a Graph object from a NetDef, which stores connections. * 2) Pattern Matches on the Graph, to find subgraphs it wants to change. * 3) Replaces the subgraphs that it's matched with new operators. * 4) Creates a NetDef from the changed Graph, and returns it. * * The effect of a Transform is defined by its 3 protected virtual functions. * 1) PatternRule determines for an ordered subgraph and a node, whether to * consider adding the node to the subgraph. * 2) ValidatorRule determines, for an ordered subgraph, whether it is a * match. * 3) ReplaceRule mutates the graph, based on a matched subgraph. * * This is the base class for all derived classes to base off. To create your * own transform, write your implementations for PatternRule, ValidatorRule, and * ReplaceRule. */ class TORCH_API Transform { public: Transform() {} /** * Apply a Transform onto a NetDef. * Returns the transformed NetDef. */ NetDef ApplyTo(const NetDef& orig_net_def); virtual ~Transform() {} /** * Determines the type of subgraphs that PatternMatch will find. * * CONNECTED_SUBGRAPH will only match subgraphs that are connected. * These subgraphs satisfy that every node of the match is connected to the * subgraph of the nodes that come before it. * For example, in the graph (1) --> (2) --> (3) --> (4), * This is capable of matching the subgraph [2, 3] and [4, 3] * This is not capable of matching the subgraph [2, 4]. * * * SORTED_WRT_EXECUTION_ORDER will match subgraphs that guarantee * sorted execution order. * The nodes don't have to be connected. It is faster than General. * For example, in the graph (1) --> (2) --> (3) --> (4), * This is capable of matching the subgraph [2, 4], [3, 4]. * This is not capable of matching the subgraph [3, 1], [4, 3]. * * * GENERAL can match any subgraph. * For example, in the graph (1) --> (2) --> (3) --> (4), * This is capable of matching subgraphs [2, 4], [3, 4], [4, 2, 1]. * There is no ordered subgraph of G that cannot be matched by this. */ enum PatternMatchType { CONNECTED_SUBGRAPH, SORTED_WRT_EXECUTION_ORDER, GENERAL }; /** * Generates all matches (stored as ordered subgraphs) and returns them. * * A match is stored as vector<int>, which is a mapping to OperatorDefs * in Graph. The order matters. */ std::vector<std::vector<int>> PatternMatch(const transform::Graph& graph); /** * Applies the replace rule onto each of the matches found. */ void ReplacePattern( const std::vector<std::vector<int>>& matches, transform::Graph* graph); protected: /** * The PatternRule essentially answers: * Given the current subgraph (ordered), should we append the new node at idx? */ virtual bool PatternRule( const transform::Graph& g, const std::vector<int>& subgraph, int /*idx*/) { CAFFE_NOT_IMPLEMENTED; } /** * The ValidatorRule essentially answers: * Given a subgraph, can we accept it? */ virtual bool ValidatorRule( const transform::Graph& g, const std::vector<int>& subgraph) { CAFFE_NOT_IMPLEMENTED; } /** * The ReplaceRule actually mutates the graph, and applies the transformation * upon the subgraph. */ virtual bool ReplaceRule( const std::vector<int>& subgraph, transform::Graph* g_ptr) { CAFFE_NOT_IMPLEMENTED; } void SetPatternMatchType(PatternMatchType type) { pattern_match_type_ = type; } private: /** * A helper function for PatternMatch, which keeps track of the best subgraph * so far. */ void PatternMatchHelper( const transform::Graph& graph, const std::vector<bool>& matched, std::vector<int>* subgraph_ptr, std::vector<int>* best_subgraph_ptr); /** * Attempts to append each neighbor to the end of the subgraph. */ void TryNeighbors( const transform::Graph& graph, const std::map<int, std::vector<string>>& neighbors, const std::vector<bool>& matched, std::vector<int>* subgraph_ptr, std::vector<int>* best_subgraph_ptr); PatternMatchType pattern_match_type_ = CONNECTED_SUBGRAPH; }; // Creates a Transform based on a key, which should be defined in registry. TORCH_API unique_ptr<Transform> CreateTransform(string key); C10_DECLARE_REGISTRY(TransformRegistry, Transform); #define REGISTER_TRANSFORM(name, ...) \ C10_REGISTER_CLASS(TransformRegistry, name, __VA_ARGS__) // Create a Transform object from registry, // and immediately apply it to a Netdef. TORCH_API NetDef ApplyTransform(const string& key, const NetDef& netdef); // Create a Transform object from registry, apply it to a NetDef. // Will only return the transformed net if it is faster than the old net. // This will run the init net first, will run the two nets warmup_runs times. // Then, we will take the average time of main_runs runs, and only keep the // transformed net if it is faster by a factor of improvement_threshold. TORCH_API NetDef ApplyTransformIfFaster( const string& key, const NetDef& netdef, const NetDef& init_netdef, const int warmup_runs, const int main_runs, const double improvement_threshold); } // namespace
Save
cmd:
run