Get the lates tf gpu image
docker pull tensorflow/tensorflow:latest-gpu-py3# apt-get wget
wget https://download.open-mpi.org/release/open-mpi/v4.0/openmpi-4.0.3.tar.gz
gunzip -c openmpi-4.0.3.tar.gz | tar xf -| # resync -> hard reset a branch to origin | |
| git config --global alias.resync '!git fetch origin && git reset --hard origin/$(git rev-parse --abbrev-ref HEAD)' | |
| #rebmain -> Fetches origin and rebase main | |
| git config --global alias.rebmain '!git fetch origin && git rebase origin/main' |
| import os | |
| from flask import Flask, flash, request, redirect, url_for | |
| from werkzeug.utils import secure_filename | |
| import tempfile | |
| tempdir = tempfile.mkdtemp(prefix="temp_image_upload") | |
| UPLOAD_FOLDER = tempdir | |
| ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'} |
| import os | |
| import zipfile | |
| def zip_dir(folder_path, zip_name): | |
| """ | |
| :param folder_path: Folder path which has to be zipped | |
| :param zip_name: the detsinatio zip name | |
| :return: | |
| """ |
| HOMEBREW_NO_AUTO_UPDATE=1 brew install openmpi | |
| HOMEBREW_NO_AUTO_UPDATE=1 brew install cmake | |
| HOMEBREW_NO_AUTO_UPDATE=1 brew install libuv | |
| HOROVOD_WITH_MPI=1 pip3 install horovod |
| from types import FunctionType | |
| class BaseClass: | |
| def __new__(cls, *args, **kwargs): | |
| # Creating a custom __init__ function | |
| params_string = ",".join(cls.params) # For init function arguments | |
| params_kwargs = ','.join([f"{i}={i}" for i in cls.params]) # Creating | |
| k=f"""def __init__(self,{params_string}):\n\tBaseClass.__init__(self, {params_kwargs}) |
| """ | |
| This example doesn't use summary writer . This is the easiest way to launch tensorboard without calling fit or running model with data | |
| """ | |
| from tensorflow.python import keras | |
| from tensorflow.python.keras import layers | |
| import tensorflow as tf | |
| import shutil | |
| from tensorboard import program | |
| logdir = "/tmp/my_tensorboard/" |
| from tensorflow.python import keras | |
| output_dim = 3 | |
| time_steps = 10 | |
| input_dim = 4 | |
| cells = [ | |
| keras.layers.LSTMCell(10, name="l1"), | |
| keras.layers.SimpleRNNCell(11, name="l2"), | |
| keras.layers.LSTMCell(12, name="l3"), | |
| ] |
| # source : https://stackoverflow.com/a/47802308/3534616 | |
| def get_tensor_dependencies(tensor): | |
| # If a tensor is passed in, get its op | |
| try: | |
| tensor_op = tensor.op | |
| except: | |
| tensor_op = tensor | |
| # Recursively analyze inputs |
| import horovod.tensorflow as hvd | |
| import tensorflow as tf | |
| hvd.init() | |
| hvd_r=int(hvd.rank()) | |
| #each process compute a small part of something and then compute the average etc | |
| #compute a small part | |
| x= tf.random_uniform(shape=()) | |
| #compute the average for all processes | |
| y=hvd.allreduce(x) | |
| tf.set_random_seed(hvd.rank()) |