| 178 | float_node = float_input.node() |
| 179 | |
| 180 | def patch_float(module): |
| 181 | try: |
| 182 | graphs = [module.graph] if hasattr(module, "graph") else [] |
| 183 | except RuntimeError: |
| 184 | graphs = [] |
| 185 | |
| 186 | if hasattr(module, "forward1"): |
| 187 | graphs.append(module.forward1.graph) |
| 188 | |
| 189 | for graph in graphs: |
| 190 | for node in graph.findAllNodes("aten::to"): |
| 191 | inputs = list(node.inputs()) |
| 192 | for i in [1, 2]: # dtype can be the second or third argument to aten::to() |
| 193 | if _node_get(inputs[i].node(), "value") == 5: |
| 194 | inputs[i].node().copyAttributes(float_node) |
| 195 | |
| 196 | model.apply(patch_float) |
| 197 | patch_float(model.encode_image) |