| 121 | device_node = [n for n in device_holder.graph.findAllNodes("prim::Constant") if "Device" in repr(n)][-1] |
| 122 | |
| 123 | def patch_device(module): |
| 124 | graphs = [module.graph] if hasattr(module, "graph") else [] |
| 125 | if hasattr(module, "forward1"): |
| 126 | graphs.append(module.forward1.graph) |
| 127 | |
| 128 | for graph in graphs: |
| 129 | for node in graph.findAllNodes("prim::Constant"): |
| 130 | if "value" in node.attributeNames() and str(node["value"]).startswith("cuda"): |
| 131 | node.copyAttributes(device_node) |
| 132 | |
| 133 | model.apply(patch_device) |
| 134 | patch_device(model.encode_image) |