File size: 1,425 Bytes
47d8ad6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
--- /var/folders/n8/bv7zgpwx3b9crc3mbp6zqb5w0000gn/T/tmp.eWO02SiwSF/coremltools/converters/mil/mil/passes/defs/optimize_state.py	2025-11-03 23:10:10
+++ /private/tmp/claude-501/-Users-aiden-Developer-Kino-kino/54f28767-a77e-430f-881b-85e18da4ab2e/scratchpad/.venv/lib/python3.9/site-packages/coremltools/converters/mil/mil/passes/defs/optimize_state.py	2026-07-23 21:53:13
@@ -87,7 +87,18 @@
 
         coreml_update_state_ops = self._try_find_child_coreml_update_state_ops(op)
         for coreml_update_state_op in coreml_update_state_ops:
-            before_op = block_operation_list[block_operation_list.index(op) + 1]
+            # PATCued: block_operation_list is a stale snapshot; earlier iterations
+            # may have removed ops (their enclosing_block is None). Walk forward to
+            # the next op still present in the block, else insert at block end.
+            idx = block_operation_list.index(op) + 1
+            while (
+                idx < len(block_operation_list)
+                and block_operation_list[idx].enclosing_block is None
+            ):
+                idx += 1
+            before_op = (
+                block_operation_list[idx] if idx < len(block_operation_list) else None
+            )
             scopes = self._construct_scope_info_list_from_op_scopes(op)
             with mb.scope(*scopes):
                 immediate_coreml_update_state = mb.coreml_update_state(