Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of TensorFlow operation ` IsExpensive()`?

Tags:

There is a method in OpKernel

 // Returns true iff this op kernel is considered "expensive". The
 // runtime may use this flag to optimize graph execution for example
 // to "inline" inexpensive kernels.
 virtual bool IsExpensive() { return expensive_; }

It seems that by default all operations on the GPU are considered as inexpensive whilst CPU, SYSL are flagged as expensive.

It is a bit hard to figure out the definition and effect of expensive. The is no information in the guide.

  1. Is there any specific guideline when IsExpensive should be false, true?
  2. What's the effect if an operation is flagged as expensive? So far I can only tell, that active profiling uses this just as a hint ? The only place querying this property is in the scheduler but without explaining what being inline means.
  3. In conjunction with "1." should I care about it in my custom Ops?
  4. While it makes sense, that any AsyncOp (like RemoteFusedGraphExecuteOp) is expensive, MPIAllgatherOp seems to be defined as not expensive. Isn't this a contradiction?

I am asking, because the IdentityOp is explicitly marked as inexpensive. I wonder, if I should override this method in my custom ops as well, since each CPU version (even any custom code) is flagged as expensive.

The entire logic of XLA seems to be about wether an instruction is expensive or not. So it might be an important part to consider. Therefore, a coin-toss about true/false might be not the best way to decide the return value in my custom op.