# Datasets, iterators and compiled tf.functions

**URL:** <https://discuss.ai.google.dev/t/datasets-iterators-and-compiled-tf-functions/30460>\
**Category:** General Discussion\
**Tags:** xla, datasets, help\_request\
**Created:** [December 2, 2021, 9:21pm UTC](https://discuss.ai.google.dev/t/datasets-iterators-and-compiled-tf-functions/30460 "2021-12-02T21:21:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramonmatas](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/ramonmatas/32/9229_2.png) [@ramonmatas](https://discuss.ai.google.dev/u/ramonmatas)\
**Post date:** [December 2, 2021, 9:21pm UTC](https://discuss.ai.google.dev/t/datasets-iterators-and-compiled-tf-functions/30460/1 "2021-12-02T21:21:52Z")

</div>

I am hitting some error involving XLA and data.

This is a reproducible short test:

```auto
    data = tf.data.Dataset.from_tensor_slices(list(range(10)))
    data = data.repeat()
    iterator = iter(data)

    @tf.function(jit_compile=False)
    def run(it):
        t = 0
        for _ in range(10):
            x = next(it)
            t += x
        return t

    @tf.function(jit_compile=True)
    def run_compiled(it):
        t = 0
        for _ in range(10):
            x = next(it)
            t += x
        return t

    print(run(iterator))
    print(run_compiled(iterator))

```

Basically the non-compiled version (run) works fine, while the compiled one (run\_compiled) is returning the following error:

```auto
tensorflow.python.framework.errors_impl.InternalError: Failed copying input tensor from /job:localhost/replica:0/task:0/device:CPU:0 to /job:localhost/replica:0/task:0/device:GPU:0 in order to run __inference_run_compiled_61: No unary variant device copy function found for direction: 1 and Variant type_index: tensorflow::ResourceDeleter [Op:__inference_run_compiled_61]

```

I am in the following tf version: 2.7.0-dev20210806

Any idea on what is going on?

Thanks!

---

<div class="post-metadata">

**Author:** ![Mark\_Daoust](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mark_daoust/32/411_2.png) [@Mark\_Daoust](https://discuss.ai.google.dev/u/Mark_Daoust)\
**Post date:** [December 3, 2021, 7:52pm UTC](https://discuss.ai.google.dev/t/datasets-iterators-and-compiled-tf-functions/30460/3 "2021-12-03T19:52:29Z")

</div>

The error’s a little clearer if you run it without the GPU “Detected unsupported operations when trying to compile graph”:

```auto
InvalidArgumentError: Detected unsupported operations when trying to compile
 graph __inference_run_compiled_86[_XlaMustCompile=true,config_proto=3175580994766145631,executor_type=11160318154034397263] 
on XLA_CPU_JIT: IteratorGetNext (No registered 'IteratorGetNext' OpKernel for XLA_CPU_JIT devices
compatible with node {{node IteratorGetNext}}){{node IteratorGetNext}}

```
