Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on Can't use tf.timestamp() from within @tf.function with XLA / jit_compile=True

Post

Can't use tf.timestamp() from within @tf.function with XLA / jit_compile=True

+1
−0

I would like to use tf.timestamp() when it is available (eager mode and graph mode without XLA), and use 0. (or a better fallback if there is one) when it is not available (with XLA; @tf.function(jit_compile=True)).

I tried this:

def tf_timestamp_or_zero():
    try:
        return tf.timestamp()
    except tf.python.framework.errors_impl.InvalidArgumentError:
        return 0.

#@tf.function
@tf.function(jit_compile=True)
def __call__(self):
    #...
    #t = tf.timestamp() # same error as below
    t = tf_timestamp_or_zero() # error, see below
    #...

Error:

tensorflow.python.framework.errors_impl.InvalidArgumentError:
Detected unsupported operations when trying to compile graph
_inference___call___5559[
    _XlaMustCompile=true,
    config_proto=3175580994766145631,
    executor_type=11160318154034397263
] on XLA_CPU_JIT:
Timestamp (No registered 'Timestamp' OpKernel for XLA_CPU_JIT devices
compatible with node {{node Timestamp}}){{node Timestamp}}
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Why `tf.timestamp`? (3 comments)
Why `tf.timestamp`?
mr Tsjolder‭ wrote over 1 year ago

Is there any reason why you can't use time.time() from the time package?

daniel_s‭ wrote over 1 year ago

Yes. Tensorflow is intended to be executed on GPUs or TPUs, special hardware for doing calculations in parallel. The marker for executing it in parallel is the @tf.function decorator. Inside functions which have this decorator, (when executed on a GPU or TPU) you can't use all standard python modules. Otherwise you will have buggy results or slow down the calculation significantly.

mr Tsjolder‭ wrote over 1 year ago

Of course! I forgot to execute the JITted function multiple times during my quick testing. Would it be feasible to split your function into different parts so that you could do the benchmarking outside of the JITted code?

Skipping 2 deleted comments.