<jupyter_start><jupyter_text>Comparison of `batchflow` performance with `tf` and `torch`  Models Firstly, we comapre `torch` and `tf` versions of `VGG16`. Train them on `MNIST`.  TensorFlow model<jupyter_code>%%time

%run ./tf_model.py<jupyter_output><empty_output><jupyter_text>... then restart kernel to clear GPU  Torch model<jupyter_code>%%time

%run ./torch_model.py<jupyter_output>CPU times: user 10.3 s, sys: 6.84 s, total: 17.2 s
Wall time: 11.1 s<jupyter_text>`torch` model is slightly faster.  Research Now let us compare `research` performances. We have the same experiment scheme and use four GPU units.  TensorFlow model<jupyter_code>import numpy as np
from multiprocessing import Process, Queue
import time
import matplotlib.pyplot as plt

import nvidia_smi

gpu_list = [2, 4, 5, 6]

def get_utilization(gpu_list):
    nvidia_smi.nvmlInit()
    handle = [nvidia_smi.nvmlDeviceGetHandleByIndex(i) for i in gpu_list]
    res = [nvidia_smi.nvmlDeviceGetUtilizationRates(item) for item in handle]
    return time.time(), [item.gpu for item in res]

def gpu_stat(gpu_list, forward, back):
    res = []
    while forward.empty():
        time.sleep(0.5)
        res.append(get_utilization(gpu_list))
    back.put(res)

def plot(res, gpu_list):
    times = np.array([item[0] for item in res])
    times = times - times[0]
    utilization = np.array([[item[1][j] for item in res] for j in range(len(gpu_list))])
    plt.figure(figsize=(15, 3))
    _ = [plt.plot(times, utilization[i]) for i in range(len(gpu_list))]
    plt.show()
forward = Queue()
back = Queue()

p = Process(target=gpu_stat, args=(gpu_list, forward, back))
p.start()
%%time

%run ./tf_research.py 4
forward.put('stop')
tf_res = back.get()
plot(tf_res, gpu_list)
forward = Queue()
back = Queue()

p = Process(target=gpu_stat, args=([2], forward, back))
p.start()
%%time

%run ./tf_research.py 1
forward.put('stop')
tf_res = back.get()
plot(tf_res, [2])<jupyter_output><empty_output><jupyter_text>Torch model<jupyter_code>forward = Queue()
back = Queue()

p = Process(target=gpu_stat, args=(gpu_list, forward, back))
p.start()
%%time

%run ./torch_research.py 4
forward.put('stop')
torch_res = back.get()
plot(torch_res, gpu_list)
forward = Queue()
back = Queue()

p = Process(target=gpu_stat, args=([2], forward, back))
p.start()
%%time

%run ./torch_research.py 1
forward.put('stop')
torch_res = back.get()
plot(torch_res, [2])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1435032894736842, 'fraction_numerical': 0.013980263157894737, 'mean_word_length': 4.963235294117647, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '292329', 'license': 'Apache-2.0', 'n_tokens_mistral': 940, 'n_tokens_neox': 916, 'n_words': 234, 'path': 'examples/experiments/profiling/profiling.ipynb', 'repo_name': 'abrikoseg/batchflow', 'size': '2432'}