Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Super-duper tensor logging functionality #686

Merged
merged 3 commits into from
Apr 4, 2018
Merged

Super-duper tensor logging functionality #686

merged 3 commits into from
Apr 4, 2018

Conversation

jindrahelcl
Copy link
Member

This very simple pull request adds the tf_utils.tf_print function, which prints out the value of a tensor in the debug log under the label tensorval

So easy to use! Instead of x = tf.Print(x, [x]), just from neuralmonkey.tf_utils import tf_print and x = tf_print(x: tf.Tensor, message: str = None)!

As a bonus, outputs of all @tensor-decorated functions that actually return a tf.Tensor are now tf_printed automatically, with a nicely formatted message, like <decoder.runtime_logprobs>: [[[ -1.91085453e+01 -1.91085453e+01 -1.94597607e+01, ...]

You don't have to worry about calling the py_func when you are not interested in the tensor values. The tf_print function checks that beforehand.

So, how to summon this mighty feature? Just run neuralmonkey with NEURALMONKEY_DEBUG_ENABLE=tensorval environment variable.

Copy link
Contributor

@jlibovicky jlibovicky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mně se nelíbí, že se printuje všechno nebo nic, tj. že ten tf_print printuje jenom, když je nastavená environment proměnná. Ten by měl printovat vždycky (třeba jenom kvůli tomu, abysme ho v kódu nezapomínali). Vůbec se mi nelíbí představa, že chci printit jednu věc a printí se mi všechno, obzlášť v transormeru, kde je každá vrstva model part.

Podmínku na debubg mód bych dal do toho dekorátoru spíš.

@jindrahelcl
Copy link
Member Author

jindrahelcl commented Apr 4, 2018 via email

keeping "tensorval" inside @tensor decorator
@jindrahelcl
Copy link
Member Author

jindrahelcl commented Apr 4, 2018

  • Teď si každý tf_print může specifikovat debug_label: str = None.
  • @tensor anotace jsou tf_printěný skrz debug_label="tensorval"
  • pořád se musí někde zapnout, že chceš ten svojí debug label vidět. (i když je None)
    (specificky NEURALMONKEY_DEBUG_ENABLE="muj_vysneny_label")

@jindrahelcl
Copy link
Member Author

Jestli se ti nelíbí, že se to musí explicitně zapnout, je to issue na logging modul a udělal bych to v příštím PR

@jlibovicky jlibovicky self-requested a review April 4, 2018 15:52
@jindrahelcl
Copy link
Member Author

Moje idea když se dělal ten debug log byla taková, že ty debug hlášky budou součástí codebase a ty si je budeš moct zapnout. Tj můžeš si zapnout debug z buildění konfiguráku, nebo třeba vypisování tenzorů. To, že ti debug poblije konzoli je normální, proto se to používá jen při debugování, kdy si ten výstup třeba hodíš do souboru, ze kterýho si grepuješ jen zajímavý místa.

Copy link
Contributor

@jlibovicky jlibovicky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, to je přesně to, co se mi nelíbí.

@jindrahelcl
Copy link
Member Author

Nikdo ti nebrání používat normální tf.Print během ladění svýho kódu. Tadyty tf_printy tu jsou od toho, aby v tom kódu zůstaly.

@jindrahelcl
Copy link
Member Author

Jako quick ugly fix si můžeš do ~/.bashrc dát export NEURALMONKEY_DEBUG_ENABLE="fintička" a pak používat tf_print(tensor, message, "fintička")

@jindrahelcl jindrahelcl merged commit 52d4c29 into master Apr 4, 2018
@jindrahelcl jindrahelcl deleted the tensorval branch April 4, 2018 15:58
@varisd
Copy link
Member

varisd commented Apr 4, 2018

Nechci znit jako smartass, ale nechete radej obetovat jedno odpoledne a naucit se:
https://www.tensorflow.org/programmers_guide/debugger

Uz ho mame podporovany a navic to umi mnohem vic nez jen tf.Print, umi to i breakpointy apod.

@jindrahelcl
Copy link
Member Author

Thanks, smartasss..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants