<jupyter_start><jupyter_text>CellLogger Demo<jupyter_code>%reload_ext autoreload
%autoreload 2<jupyter_output><empty_output><jupyter_text>Setup<jupyter_code>import numpy as np
import torch
from ipyexperiments import IPyExperimentsPytorch
def consume_cpu_ram(n): return np.ones((n, n))
def consume_gpu_ram(n): return torch.ones((n, n)).cuda()
def consume_cpu_ram_128mb(): return consume_cpu_ram(2**12)
def consume_gpu_ram_256mb(): return consume_gpu_ram(2**13)<jupyter_output><empty_output><jupyter_text>Main functionality<jupyter_code>exp1 = IPyExperimentsPytorch(exp_enable=False)
# consume, consume more
a1 = consume_cpu_ram_128mb()
a2 = consume_cpu_ram_128mb()
# consume, consume more, then release some (temporarily requires double the memory)
a1 = consume_cpu_ram_128mb()
a2 = consume_cpu_ram_128mb()
del a1
# consume, release, then consume more (half the memory is needed at the peak)
a1 = consume_cpu_ram_128mb()
del a1
a2 = consume_cpu_ram_128mb()
# consume, consume more, release all (all memory get reclaimed)
b1 = consume_cpu_ram_128mb()
b2 = consume_cpu_ram_128mb()
del b1
del b2
# same on gpu
c1 = consume_gpu_ram_256mb()
c2 = consume_gpu_ram_256mb()
del c1
# direct data accessor (in unrounded Bytes)
cpu_mem   = exp1.cl.data.cpu
gpu_mem   = exp1.cl.data.gpu
time_data = exp1.cl.data.time
cpu_mem
gpu_mem
time_data
gpu_mem.used_delta
exp1.cl.stop()
# there should be no log appearing, after the logger has been stopped
a = consume_cpu_ram_128mb()<jupyter_output><empty_output><jupyter_text>Automatically reset NRG seed<jupyter_code>exp2 = IPyExperimentsPytorch(exp_enable=False, cl_set_seed=42, cl_compact=True)
rnd1 = np.random.random()
rnd2 = np.random.random()
assert rnd1 == rnd2, f"values should be the same rnd1={rnd1} rnd2={rnd2}"
del exp2 # cleanup
%%javascript # prevent committing an unsaved notebook
_=IPython.notebook.save_notebook()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0984647961884595, 'fraction_numerical': 0.04129168872419269, 'mean_word_length': 7.709677419354839, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '439141', 'license': 'Apache-2.0', 'n_tokens_mistral': 743, 'n_tokens_neox': 708, 'n_words': 164, 'path': 'demo_cl.ipynb', 'repo_name': 'stas00/ipyexperiments', 'size': '1889'}