MCPcopy Index your code
hub / github.com/pytorch/pytorch / build_cache_step

Method build_cache_step

caffe2/python/cached_reader.py:93–122  ·  view source on GitHub ↗

Build a step for generating cache DB file. If self.db_path exists and not overwritting, build an empty step. Overwise, build a step as follows. Pipe original reader to the _DatasetWriter, so that dataset field blobs are populated. Then sav

(self, overwrite=False)

Source from the content-addressed store, hash-verified

91 return self.original_reader._schema
92
93 def build_cache_step(self, overwrite=False):
94 """Build a step for generating cache DB file.
95
96 If self.db_path exists and not overwritting, build an empty step.
97 Overwise, build a step as follows.
98 Pipe original reader to the _DatasetWriter,
99 so that dataset field blobs are populated.
100 Then save these blobs into a file.
101
102 Args:
103 overwrite: bool. If true, ignore the existing file
104 and build a new one overwritting the existing one anyway.
105
106 Returns:
107 build_cache_step: ExecutionStep.
108 The step to be run for building a cache DB file.
109 """
110 if os.path.exists(self.db_path) and not overwrite:
111 # cache already exists, no need to rebuild it
112 return core.execution_step('build_step', [])
113
114 init_net = core.Net('init')
115 self._init_field_blobs_as_empty(init_net)
116 with Cluster(), core.NameScope(self.name), TaskGroup() as copy_tg:
117 pipe(self.original_reader, self.ds.writer(), num_threads=16)
118 copy_step = copy_tg.to_task().get_step()
119 save_net = core.Net('save')
120 self._save_field_blobs_to_db_file(save_net)
121
122 return core.execution_step('build_cache', [init_net, copy_step, save_net])
123
124 def _save_field_blobs_to_db_file(self, net):
125 """Save dataset field blobs to a DB file at db_path"""

Callers 2

test_cached_readerMethod · 0.95
test_db_file_readerMethod · 0.95

Calls 10

ClusterClass · 0.90
TaskGroupClass · 0.90
pipeFunction · 0.90
execution_stepMethod · 0.80
NetMethod · 0.80
get_stepMethod · 0.80
to_taskMethod · 0.80
writerMethod · 0.45

Tested by 2

test_cached_readerMethod · 0.76
test_db_file_readerMethod · 0.76