In general (for models that are supporting it), the resource variables will be hoisted outside of the function intended to be compiler to make it “pure”.
See for example this pass pipeline which is our flow to target TPUs: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/compiler/mlir/tensorflow/transforms/bridge.cc#L136 2