| 141 | float_node = float_input.node() |
| 142 | |
| 143 | def patch_float(module): |
| 144 | graphs = [module.graph] if hasattr(module, "graph") else [] |
| 145 | if hasattr(module, "forward1"): |
| 146 | graphs.append(module.forward1.graph) |
| 147 | |
| 148 | for graph in graphs: |
| 149 | for node in graph.findAllNodes("aten::to"): |
| 150 | inputs = list(node.inputs()) |
| 151 | for i in [1, 2]: # dtype can be the second or third argument to aten::to() |
| 152 | if inputs[i].node()["value"] == 5: |
| 153 | inputs[i].node().copyAttributes(float_node) |
| 154 | |
| 155 | model.apply(patch_float) |
| 156 | patch_float(model.encode_image) |