Retrieve tensorflow device placement logging in a variable

Hi,

I would like to retrieve tensorflow device placement as data I can manipulate from within python.
I use tf.debugging.set_log_device_placement(True) to log the device placement to stderr, however I haven’t found a way to catch it into a variable.

I tried both using contextlib.redirect_stderr and adding a StreamHandler to tf.get_logger(), none of these resulted in the logging output being caught.

See my original question from stack overflow.

I think that we don’t have a python API to do this as I suppose it is done at c++ level:

Alright fair enough.
I wonder though why python’s contextlib.redirect_stderr isn’t able to catch it… But that’s more of a python question than a tensorflow. But if anyone knows answer I take it :slight_smile:

Yes, you could try to take a look at:

https://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/

1 Like

Awesome, thank you for the link!