{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Running Tensorboard from Jupyter lab\n", "====================================\n", "---\n", "Introduction au Deep Learning (IDLE) - S. Arias, E. Maldonado, JL. Parouty - CNRS/SARI/DEVLOG - 2020 \n", "Vesion : 1.0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1/ Méthode 1 : Shell execute\n", "### 1.1/ Start/stop" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Tensorbord started - pid is 9934\n", "12399\n" ] } ], "source": [ "%%bash\n", "tensorboard_start --logdir ./run/logs" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Tensorboard status - not found...\n" ] } ], "source": [ "%%bash\n", "tensorboard_status" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Tensorbord stopped - pid was 9934\n" ] } ], "source": [ "%%bash\n", "tensorboard_stop" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1.3/ Scripts" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Overwriting /home/paroutyj/bin/tensorboard_start\n" ] } ], "source": [ "%%writefile \"~/bin/tensorboard_start\"\n", "\n", "#!/bin/bash\n", "#\n", "# -----------------------------------------------------------\n", "# _____ _ _ \n", "# |_ _|__ _ __ ___ ___ _ __| |__ ___ __ _ _ __ __| |\n", "# | |/ _ \\ '_ \\/ __|/ _ \\| '__| '_ \\ / _ \\ / _` | '__/ _` |\n", "# | | __/ | | \\__ \\ (_) | | | |_) | (_) | (_| | | | (_| |\n", "# |_|\\___|_| |_|___/\\___/|_| |_.__/ \\___/ \\__,_|_| \\__,_|\n", "# Start\n", "# -----------------------------------------------------------\n", "# Start tensorboard, with calculate port number and good host\n", "# -----------------------------------------------------------\n", "# Jean-Luc Parouty CNRS/SIMaP Janvier 2020 - version 1.02\n", "\n", "VERSION='1.2'\n", "CONDA_ENV='GPU'\n", "HOST_FRONT='f-dahu'\n", "\n", "# ---- Usage\n", "#\n", "if [ \"$1\" == \"-?\" ] || [ $# -eq 0 ]; then\n", " echo -e \"Start tensorboard in GRICAD environment. (v$VERSION)\"\n", " echo -e \"Usage: $(basename $0) -h | --logdir <logdir> [tensorboard args]\"\n", " echo -e \"Exemple : $(basename $0) --logdir ./run/logs\\n\"\n", " exit\n", "fi\n", " \n", "# ---- Conda activate\n", "#\n", "source /applis/environments/conda.sh\n", "conda activate \"$CONDA_ENV\" >/dev/null 2>&1\n", "status=$?\n", "if [ $status -ne 0 ]; then\n", " echo -e \"Oups ! Conda environment is not available... contact your support ;-(\\n\"\n", " exit 1\n", "fi\n", " \n", "# ---- Port number\n", "#\n", "PORT_JPY=\"$(/usr/bin/id -u)\"\n", "PORT_TSB=\"$(( $PORT_JPY + 10000 ))\"\n", " \n", "# ---- tmpdir (tmp bug)\n", "#\n", "export TMPDIR=\"/tmp/$(/usr/bin/id -un)\"\n", "/bin/mkdir -p \"$TMPDIR\"\n", "\n", "# ---- Start it\n", "#\n", "tensorboard --port $PORT_TSB --host 0.0.0.0 $@ &>/dev/null &\n", " \n", "# ---- Where is it ?\n", "#\n", "sleep 5\n", "p=\"$(/bin/ps ax | /bin/grep \"tensorboard --port $PORT_TSB\" | /bin/grep -v grep | awk '{print $1}')\"\n", "if [ -z \"$p\" ]; then\n", " echo \"Tensorboard didn't start... check your parameters !\"\n", " exit\n", "else\n", " echo \"Tensorbord started - pid is $p\"\n", "fi\n", " \n", "# ---- Not on a node ? we give the tunnel\n", "#\n", "if [ \"$(hostname)\" == $HOST_FRONT ]\n", "then\n", " SSH_CMD=\"/usr/bin/ssh -NL 6006:$HOST_FRONT:$PORT_TSB dahu.ciment\"\n", " echo -e \"SSH Tunnel : \\e[93m$SSH_CMD \\e[0m\\n\"\n", "fi\n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%writefile \"~/bin/tensorboard_status\"\n", "\n", "#!/bin/bash\n", "#\n", "# -----------------------------------------------------------\n", "# _____ _ _ \n", "# |_ _|__ _ __ ___ ___ _ __| |__ ___ __ _ _ __ __| |\n", "# | |/ _ \\ '_ \\/ __|/ _ \\| '__| '_ \\ / _ \\ / _` | '__/ _` |\n", "# | | __/ | | \\__ \\ (_) | | | |_) | (_) | (_| | | | (_| |\n", "# |_|\\___|_| |_|___/\\___/|_| |_.__/ \\___/ \\__,_|_| \\__,_|\n", "# Status\n", "# -----------------------------------------------------------\n", "# Stop tensorboard previously started with tensorboard_start\n", "# -----------------------------------------------------------\n", "# Jean-Luc Parouty CNRS/SIMaP Janvier 2020\n", "\n", "VERSION=\"1.02\"\n", "\n", "# ---- Usage\n", "#\n", "if [ \"$1\" == \"-?\" ] ; then\n", " echo -e \"Tensorboard status in GRICAD environment. (v$VERSION)\"\n", " echo -e \"Usage: $(basename $0) [-h ]\"\n", " echo -e \"Exemple : $(basename $0)\\n\"\n", " exit\n", "fi\n", "\n", "# ---- Process id\n", "#\n", "PORT_JPY=\"$(id -u)\"\n", "PORT_TSB=\"$(( $PORT_JPY + 10000 ))\"\n", "\n", "# ---- Where is it ?\n", "#\n", "p=\"$(ps ax | grep \"tensorboard --port $PORT_TSB\" | grep -v grep | awk '{print $1}')\"\n", "if [ -z \"$p\" ]; then\n", " echo \"Tensorboard status - not found...\"\n", "else\n", " echo \"Tensorboard status - pid is $p\"\n", "fi" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%writefile \"~/bin/tensorboard_stop\"\n", "\n", "#!/bin/bash\n", "#\n", "# -----------------------------------------------------------\n", "# _____ _ _ \n", "# |_ _|__ _ __ ___ ___ _ __| |__ ___ __ _ _ __ __| |\n", "# | |/ _ \\ '_ \\/ __|/ _ \\| '__| '_ \\ / _ \\ / _` | '__/ _` |\n", "# | | __/ | | \\__ \\ (_) | | | |_) | (_) | (_| | | | (_| |\n", "# |_|\\___|_| |_|___/\\___/|_| |_.__/ \\___/ \\__,_|_| \\__,_|\n", "# Stop\n", "# -----------------------------------------------------------\n", "# Stop tensorboard previously started with tensorboard_start\n", "# -----------------------------------------------------------\n", "# Jean-Luc Parouty CNRS/SIMaP Janvier 2020\n", "\n", "VERSION=\"1.02\"\n", "\n", "# ---- Usage\n", "#\n", "if [ \"$1\" == \"-?\" ] ; then\n", " echo -e \"Stop tensorboard in GRICAD environment. (v$VERSION)\"\n", " echo -e \"Usage: $(basename $0) [-h ]\"\n", " echo -e \"Exemple : $(basename $0)\\n\"\n", " exit\n", "fi\n", "\n", "# ---- Process id\n", "#\n", "PORT_JPY=\"$(id -u)\"\n", "PORT_TSB=\"$(( $PORT_JPY + 10000 ))\"\n", "\n", "# ---- Where is it ?\n", "#\n", "p=\"$(ps ax | grep \"tensorboard --port $PORT_TSB\" | grep -v grep | awk '{print $1}')\"\n", "if [ -z \"$p\" ]; then\n", " echo \"Tensorboard process not found...\"\n", "else\n", " kill $p\n", " echo \"Tensorbord stopped - pid was $p\"\n", "fi" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Set scripts privileges :**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%bash\n", "/bin/chmod 755 ~/bin/tensorboard_* 2>/dev/null\n", "/bin/ls -l ~/bin/tensorboard_* 2>/dev/null" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Check**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Méthode 2 : Magic command\n", "**Start**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%load_ext tensorboard" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%tensorboard --port 21277 --host 0.0.0.0 --logdir ./run/logs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Stop** \n", "No way... use bash method\n", "\n", "## Methode 3 : Tensorboard module\n", "\n", "**Start**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import tensorboard.notebook as tsb" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tsb.start('--port 21277 --host 0.0.0.0 --logdir ./run/logs')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Check**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a=tsb.list()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Stop** \n", "No way... use bash method" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!kill 214798" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.5" } }, "nbformat": 4, "nbformat_minor": 4 }