MCPcopy Create free account
hub / github.com/pytorch/executorch / preprocess

Method preprocess

backends/vulkan/vulkan_preprocess.py:126–252  ·  view source on GitHub ↗
(  # noqa: C901
        cls,
        program: ExportedProgram,
        module_compile_spec: List[CompileSpec],
    )

Source from the content-addressed store, hash-verified

124 @classmethod
125 # pyre-ignore
126 def preprocess( # noqa: C901
127 cls,
128 program: ExportedProgram,
129 module_compile_spec: List[CompileSpec],
130 ) -> PreprocessResult:
131 compile_options = parse_compile_spec(module_compile_spec)
132
133 default_texture_limits = copy.deepcopy(utils.DEFAULT_TEXTURE_LIMITS)
134 # 2048 is the typical limit value for 3D textures, but mobile GPUs often support
135 # 16384. Since the Vulkan delegate primarily targets mobile GPUs at the moment,
136 # 16394 is the default texture limit used. This option is provided as a
137 # convenient way to switch to using a limit of 2048 for image textures which
138 # will be compatible with most GPUs.
139 if compile_options.get("small_texture_limits", False):
140 default_texture_limits[0] = 2048
141 default_texture_limits[1] = 2048
142 default_texture_limits[2] = 2048
143
144 limits_x = compile_options.get("texture_limits_x", default_texture_limits[0])
145 limits_y = compile_options.get("texture_limits_y", default_texture_limits[1])
146 limits_z = compile_options.get("texture_limits_z", default_texture_limits[2])
147 texture_limits = (limits_x, limits_y, limits_z)
148
149 default_storage_type = compile_options.get(
150 "storage_type_override", VkStorageType.TEXTURE_3D
151 )
152 default_memory_layout = compile_options.get(
153 "memory_layout_override", VkMemoryLayout.TENSOR_WIDTH_PACKED
154 )
155 downcast_64_bit = compile_options.get("downcast_64_bit", True)
156 force_fp16 = compile_options.get("force_fp16", False)
157
158 program = unsafe_remove_auto_functionalized_pass(program)
159
160 # First, apply passes that fuse/remove operators to consolidate the graph
161 # structure but still preserve an "ATen-compliant" graph structure (i.e. all
162 # arguments to ATen operators must match the ATen function schema).
163 program = apply_passes(
164 program,
165 [
166 AddmmToLinearTransform(),
167 FuseBatchNormPass(program),
168 AddmmToLinearTransform(),
169 InsertDtypePromotionPass(),
170 FusePatternsPass(),
171 FuseClampPass(),
172 RemoveRedundantOpsTransform(),
173 FuseQuantizedOpsTransform(),
174 FoldQDQPass(),
175 SqueezeUnsqueezeInputs(),
176 FuseViewCopyTransform(),
177 ViewCopyToSqueezeUnsqueezePass(),
178 ],
179 )
180
181 # Next annotate tensor nodes with TensorSpec structs which is needed for dynamic
182 # shapes and memory planning. Until this point, the graph must be ATen compliant
183 # because SpecPropPass will be calling the underlying ATen operators during its

Callers

nothing calls this directly

Calls 15

build_graphMethod · 0.95
FuseBatchNormPassClass · 0.90
FusePatternsPassClass · 0.90
FuseClampPassClass · 0.90
FoldQDQPassClass · 0.90

Tested by

no test coverage detected