| 158 | float_node = float_input.node() |
| 159 | |
| 160 | def patch_float(module): |
| 161 | try: |
| 162 | graphs = [module.graph] if hasattr(module, "graph") else [] |
| 163 | except RuntimeError: |
| 164 | graphs = [] |
| 165 | |
| 166 | if hasattr(module, "forward1"): |
| 167 | graphs.append(module.forward1.graph) |
| 168 | |
| 169 | for graph in graphs: |
| 170 | for node in graph.findAllNodes("aten::to"): |
| 171 | inputs = list(node.inputs()) |
| 172 | for i in [1, 2]: # dtype can be the second or third argument to aten::to() |
| 173 | if inputs[i].node()["value"] == 5: |
| 174 | inputs[i].node().copyAttributes(float_node) |
| 175 | |
| 176 | model.apply(patch_float) |
| 177 | patch_float(model.encode_image) |