<jupyter_start><jupyter_text>Introduction to colabColab is Google's version of Jupyter notebooks, but has the following advantages:- it runs in the cloud, not locally, so you can use it from a cheap laptop, such as a Chromebook. - The notebook is saved in your Google drive, so you can share your notebook with someone else and work on it collaboratively.- it has nearly all of the packages you need for doing ML pre-installed- it gives you free access to GPUs- it has a [file editor](https://colab.research.google.com/github/probml/pyprobml/blob/master/book1/supplements/colab_intro.ipynbscrollTo=DdXlYCe1AlJa&line=7&uniqifier=1), so you can separate your code from the output of your code, as with other IDEs, such as [Jupyter lab](https://jupyterlab.readthedocs.io/en/stable/).- it has various other useful features, such as collapsible sections (cf. code folding), and ways to specify parameters to your functions via [various GUI widgets](https://colab.research.google.com/notebooks/forms.ipynb) for use by non-programmers. (You can automatically execute  parameterized notebooks with different parameters using [papermill](https://papermill.readthedocs.io/en/latest/).)More details can be found in the [official introduction](https://colab.research.google.com/notebooks/intro.ipynb). Below we describe a few more tips and tricks, focusing on methods that I have found useful when developing the book. (More advanced tricks can be found in [this blog post](https://amitness.com/2020/06/google-colaboratory-tips/) and [this blog post](https://medium.com/@robertbracco1/configuring-google-colab-like-a-pro-d61c253f75734cf4).)<jupyter_code>IS_COLAB = ('google.colab' in str(get_ipython()))
print(IS_COLAB)

# Standard Python libraries
from __future__ import absolute_import, division, print_function, unicode_literals

import os
import time
import glob

from typing import Any, Callable, Dict, Iterator, Mapping, Optional, Sequence, Tuple<jupyter_output><empty_output><jupyter_text>How to import and use standard libraries Colab comes with most of the packages we need pre-installed. You can see them all using this command.<jupyter_code>!pip list -v<jupyter_output>Package                       Version         Location                               Installer
----------------------------- --------------- -------------------------------------- ---------
absl-py                       0.10.0          /usr/local/lib/python3.6/dist-packages pip      
alabaster                     0.7.12          /usr/local/lib/python3.6/dist-packages pip      
albumentations                0.1.12          /usr/local/lib/python3.6/dist-packages pip      
altair                        4.1.0           /usr/local/lib/python3.6/dist-packages pip      
argon2-cffi                   20.1.0          /usr/local/lib/python3.6/dist-packages pip      
asgiref                       3.3.1           /usr/local/lib/python3.6/dist-packages pip      
astor                         0.8.1           /usr/local/lib/python3.6/dist-packages pip      
astropy                       4.1             /usr/local/lib/python3.6/dist-packages pip      
astunparse                    1.6.3           /usr[...]<jupyter_text>To install a new package called 'foo', use the following (see [this page](https://colab.research.google.com/notebooks/snippets/importing_libraries.ipynb) for details):```!pip install foo```  Numpy<jupyter_code>import numpy as np
np.set_printoptions(precision=3)

A = np.random.randn(2,3)
print(A)<jupyter_output>[[0.414 1.496 0.64 ]
 [0.953 1.708 0.251]]<jupyter_text>Pandas<jupyter_code>import pandas as pd
pd.set_option('precision', 2) # 2 decimal places
pd.set_option('display.max_rows', 20)
pd.set_option('display.max_columns', 30)
pd.set_option('display.width', 100) # wide windows

url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data'
column_names = ['MPG','Cylinders','Displacement','Horsepower','Weight',
                'Acceleration', 'Year', 'Origin', 'Name']
df = pd.read_csv(url, names=column_names, sep='\s+', na_values="?")

df.head()<jupyter_output><empty_output><jupyter_text>Sklearn<jupyter_code>import sklearn

from sklearn.datasets import load_iris
iris = load_iris()
# Extract numpy arrays
X = iris.data 
y = iris.target

import matplotlib.pyplot as plt
plt.scatter(X[:,0], X[:,1])<jupyter_output><empty_output><jupyter_text>JAX<jupyter_code># JAX (https://github.com/google/jax)

import jax
import jax.numpy as jnp
A = jnp.zeros((3,3))

# Check if JAX is using GPU
print("jax backend {}".format(jax.lib.xla_bridge.get_backend().platform))<jupyter_output>jax backend gpu<jupyter_text>Tensorflow<jupyter_code>import tensorflow as tf
from tensorflow import keras
assert tf.__version__ >= "2.0"

print("tf version {}".format(tf.__version__))
print([d for d in tf.config.list_physical_devices()])

if not tf.config.list_physical_devices('GPU'):
    print("No GPU was detected. DNNs can be very slow without a GPU.")
    if IS_COLAB:
        print("Go to Runtime > Change runtime and select a GPU hardware accelerator.")<jupyter_output>tf version 2.4.0
[PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'), PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]<jupyter_text>PyTorch<jupyter_code>import torch
import torchvision
print("torch version {}".format(torch.__version__))
if torch.cuda.is_available():
    print(torch.cuda.get_device_name(0))
else:
    print("Torch cannot find GPU")<jupyter_output>torch version 1.7.0+cu101
Tesla T4<jupyter_text>PlottingColab has excellent support for plotting. We give some examples below.  Static plotsColab lets you make static plots using matplotlib, as shown below.Note that plots are displayed inline by default, so```%matplotlib inline```is not needed.<jupyter_code>import matplotlib.pyplot as plt
import PIL
import imageio
import seaborn as sns;
seaborn.set()
seaborn.set_style("whitegrid")

plt.rcParams.update({'font.size': 48, 'legend.fontsize': 18})
plt.rc('xtick',labelsize=14)
plt.rc('ytick',labelsize=14)

from IPython.display import display

plt.figure()
plt.plot(range(10))
plt.savefig('myplot.png')<jupyter_output><empty_output><jupyter_text>Interactive plotsColab also lets you create interactive plots using various javascript libraries - see [here](https://colab.research.google.com/notebooks/charts.ipynbscrollTo=QSMmdrrVLZ-N) for details.Below we illustrate how to use the [bokeh library](https://docs.bokeh.org/en/latest/index.html) to create an interactive plot of a  pandas time series, where if you mouse over the plot, it shows the corresponding (x,y) coordinates. (Another option is [plotly](https://plotly.com/graphing-libraries/).)<jupyter_code>import pandas as pd
import numpy as np
from bokeh.plotting import figure, show
from bokeh.io import output_notebook
from bokeh.models import ColumnDataSource, HoverTool

# Call once to configure Bokeh to display plots inline in the notebook.
output_notebook()




np.random.seed(0)
dates = pd.date_range(start='2018-04-24', end='2018-08-27')
N = len(dates)
vals = np.random.standard_t(1, size=N)
dd = pd.DataFrame({'vals': vals, 'dates': dates}, index=dates)
dd['days'] = dd.dates.dt.strftime("%Y-%m-%d")


source = ColumnDataSource(dd)
hover = HoverTool(tooltips=[("Date", "@days"),
                            ("vals", "@vals")],
)
p = figure( x_axis_type="datetime")
p.line(x='dates', y='vals', source=source)
p.add_tools(hover)
show(p)<jupyter_output><empty_output><jupyter_text>When you mouse over a point, you should see something like the screenshot below.<img height="500" src="https://github.com/probml/pyprobml/blob/master/book1/intro/figures/bokeh-timeseries.png?raw=true"> We can also make plots that can you pan and zoom into.<jupyter_code>N = 4000
np.random.seed(0)
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
radii = np.random.random(size=N) * 1.5
colors = ["#%02x%02x%02x" % (r, g, 150) for r, g in zip(np.floor(50+2*x).astype(int), np.floor(30+2*y).astype(int))]

p = figure()
p.circle(x, y, radius=radii, fill_color=colors, fill_alpha=0.6, line_color=None)
show(p)<jupyter_output><empty_output><jupyter_text>GraphvizYou can use graphviz to layout nodes of a graph and draw the structure.<jupyter_code>!apt-get -y install python-pydot
!apt-get -y install python-pydot-ng
!apt-get -y install graphviz
from graphviz import Digraph
dot = Digraph(comment='Bayes net')
print(dot)
dot.node('C', 'Cloudy')
dot.node('R', 'Rain')
dot.node('S', 'Sprinkler')
dot.node('W', 'Wet grass')
dot.edge('C', 'R')
dot.edge('C', 'S')
dot.edge('R', 'W')
dot.edge('S', 'W')
print(dot.source) 
dot.render('test-output/graph.jpg', view=True)
dot<jupyter_output>// Bayes net
digraph {
}
// Bayes net
digraph {
	C [label=Cloudy]
	R [label=Rain]
	S [label=Sprinkler]
	W [label="Wet grass"]
	C -> R
	C -> S
	R -> W
	S -> W
}<jupyter_text>Progress bar<jupyter_code>! pip install fastprogress
from fastprogress import master_bar, progress_bar
my_list = np.arange(0,100)
N = 1000
for item in progress_bar(my_list):
    np.dot(np.ones((N,N)), np.ones((N,N)))<jupyter_output><empty_output><jupyter_text>Filing system issues  Accessing local filesClicking on the file folder icon on the left hand side of colab lets you browse local files. Right clicking on a filename lets you download it to your local machine. Double clicking on a file will open it in the file viewer/ editor, which appears on the right hand side. The result should look something like this:<img src="https://github.com/probml/pyprobml/blob/master/book1/intro/figures/colab-image-viewer.png?raw=true">You can also use standard unix commands to manipulate files, as we show below.<jupyter_code>!pwd
!ls
!echo 'foo bar' > foo.txt
!cat foo.txt<jupyter_output>foo bar<jupyter_text>You can open text files in the editor by clicking on their filename in the file browser, or programmatically as shown below.<jupyter_code>from google.colab import files
files.view('foo.txt')<jupyter_output><empty_output><jupyter_text>If you make changes to a file containing code, the new version of the file will not be noticed unless you use the magic below.<jupyter_code>%load_ext autoreload
%autoreload 2<jupyter_output>The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload<jupyter_text>Syncing with Google driveFiles that you generate in, or upload to, colab are ephemeral, since colab is a temporary environment with an idle timeout of 90 minutes and an absolute timeout of 12 hours (24 hours for Colab pro). To save any files permanently, you need to mount your google drive folder as we show below. (Executing this command will open a new window in your browser - you need cut and paste the password that is shown into the prompt box.)<jupyter_code>from google.colab import drive
drive.mount('/content/gdrive')
!pwd


with open('/content/gdrive/MyDrive/foo.txt', 'w') as f:
  f.write('Hello Google Drive!')
!cat /content/gdrive/MyDrive/foo.txt<jupyter_output>Hello Google Drive!<jupyter_text>To ensure that local changes are detected by colab, use this piece of magic.<jupyter_code>%load_ext autoreload
%autoreload 2<jupyter_output><empty_output><jupyter_text>Downloading dataYou can use [wget](https://www.pair.com/support/kb/paircloud-downloading-files-with-wget/)<jupyter_code>!pwd
!rm timemachine.*

#!wget  https://github.com/probml/pyprobml/blob/master/data/timemachine.txt

!wget https://raw.githubusercontent.com/probml/pyprobml/master/data/timemachine.txt
!head timemachine.txt<jupyter_output>The Time Machine, by <NAME> [1898]

I

The Time Traveller (for so it will be convenient to speak of him) was expounding a recondite matter to us. His grey eyes shone and twinkled, and his usually pale face was flushed and animated. The fire burned brightly, and the soft radiance of the incandescent lights in the lilies of silver caught the bubbles that flashed and passed in our glasses. Our chairs, being his patents, embraced and caressed us rather than submitted to be sat upon, and there was that luxurious after-dinner atmosphere when thought roams gracefully free of the trammels of precision. And he put it to us in this way--marking the points with a lean forefinger--as we sat and lazily admired his earnestness over this new paradox (as we thought it) and his fecundity.

'You must follow me carefully. I shall have to controvert one or two ideas that are almost universally accepted. The geometry, for instance, they taught you at school is founded on a misconception.'

'Is not tha[...]<jupyter_text>Viewing all your notebooksYou can see the list of colab notebooks that you have saved as shown below.<jupyter_code>import re, pathlib, shutil
from pathlib import PosixPath

# Get a list of all your Notebooks
notebooks = [x for x in pathlib.Path("/content/gdrive/MyDrive/Colab Notebooks").iterdir() if 
             re.search(r"\.ipynb", x.name, flags = re.I)]
print(notebooks[:2])

#n = PosixPath('/content/gdrive/MyDrive/Colab Notebooks/covid-open-data-paper.ipynb')<jupyter_output>[PosixPath('/content/gdrive/MyDrive/Colab Notebooks/saining-cvpr18-video-3d.ipynb'), PosixPath('/content/gdrive/MyDrive/Colab Notebooks/Copy of Getting started with pytorch.ipynb')]<jupyter_text>Working with githubYou can open any jupyter notebook stored in github in a colab by replacinghttps://github.com/probml/.../intro.ipynb with https://colab.research.google.com/github/probml/.../intro.ipynb (see [this blog post](https://amitness.com/2020/06/google-colaboratory-tips/6-open-notebooks-from-github).It is possible to download code (or data) from githib into a local directory on this virtual machine.  It is also possible to upload local files back to github, although that is more complex. See details below.  Cloning a repo from githubYou can clone a public github repo into your local colab VM, as we show below,using the repo for this book as an example.(To clone a private repo, you need to specify your password,as explained [here](https://medium.com/@robertbracco1/configuring-google-colab-like-a-pro-d61c253f75736b70). Alternatively you can use the ssh method we describe below.)<jupyter_code>!rm -rf pyprobml # Remove any old local directory to ensure fresh install
!git clone https://github.com/probml/pyprobml

!pwd
!ls<jupyter_output>pyprobml  sample_data<jupyter_text>We can access data as shown below.<jupyter_code>datadir = 'pyprobml/data'
import re
fname = os.path.join(datadir, 'timemachine.txt')
with open(fname, 'r') as f:
    lines = f.readlines()
    sentences = [re.sub('[^A-Za-z]+', ' ', st).lower().split()
                   for st in lines]
for  i in range(5):
  words = sentences[i]
  print(words)<jupyter_output>['the', 'time', 'machine', 'by', 'h', 'g', 'wells']
[]
['i']
[]
['the', 'time', 'traveller', 'for', 'so', 'it', 'will', 'be', 'convenient', 'to', 'speak', 'of', 'him', 'was', 'expounding', 'a', 'recondite', 'matter', 'to', 'us', 'his', 'grey', 'eyes', 'shone', 'and', 'twinkled', 'and', 'his', 'usually', 'pale', 'face', 'was', 'flushed', 'and', 'animated', 'the', 'fire', 'burned', 'brightly', 'and', 'the', 'soft', 'radiance', 'of', 'the', 'incandescent', 'lights', 'in', 'the', 'lilies', 'of', 'silver', 'caught', 'the', 'bubbles', 'that', 'flashed', 'and', 'passed', 'in', 'our', 'glasses', 'our', 'chairs', 'being', 'his', 'patents', 'embraced', 'and', 'caressed', 'us', 'rather', 'than', 'submitted', 'to', 'be', 'sat', 'upon', 'and', 'there', 'was', 'that', 'luxurious', 'after', 'dinner', 'atmosphere', 'when', 'thought', 'roams', 'gracefully', 'free', 'of', 'the', 'trammels', 'of', 'precision', 'and', 'he', 'put', 'it', 'to', 'us', 'in', 'this', 'way', 'marking', 'the', 'points', 'with', [...]<jupyter_text>We can run any script as shown below.(Note we first have to define the environment variable for where the figures will be stored.)<jupyter_code>import os
os.environ['PYPROBML']='pyprobml'

%run pyprobml/scripts/activation_fun_plot.py
!ls pyprobml/figures<jupyter_output>activationFuns2.pdf  Elephant_mating_ritual_3.jpg   sigmoid_saturation_plot.png
activationFuns.pdf   github-vscode-browser.png
cat_dog.jpg	     Serengeti_Elefantenherde2.jpg<jupyter_text>We can also import code, as we show below.<jupyter_code>!ls

import pyprobml.scripts.pyprobml_utils as pml
pml.test()<jupyter_output>welcome to python probabilistic ML library<jupyter_text>Pushing local files back to githubYou can easily save your entire colab notebook to github by choosing 'Save a copy in github' under the File menu in the top left. But if you want to save individual files (eg code that you edited in the colab file editor, or a bunch of images or data files you created), the process is more complex.There are two main methods. You can either specify your username and password every time, as explained [here](https://medium.com/@robertbracco1/configuring-google-colab-like-a-pro-d61c253f75736b70). Or you can authenticate via ssh. The latter is more secure, but more complex, as we explain below.You first need to do some setup to create SSH keys on your current colab VM (virtual machine), manually add the keys to your github account, and then copy the keys to your mounted google drive so you can reuse the same keys in the future. This only has to be done once.After setup, you can use the `git_ssh` function we define below to securely execute git commands. This works by copying your SSH keys from your google drive to the current colab VM, executing the git command, and then deleting the keys from the VM for safety.   SetupFollow these steps. (These instructions are text, not code, since they require user interaction.)```!ssh-keygen -t rsa -b 4096!ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts!cat /root/.ssh/id_rsa.pub```The cat command will display your public key in the colab window.Cut and paste this and manually add to your github account following [these instructions](https://github.com/settings/keys).Test it worked```!ssh -T git@github.com```Finally, save the generated keys to your Google drive```from google.colab import drivedrive.mount('/content/drive')!mkdir /content/drive/MyDrive/ssh/!cp  -r  ~/.ssh/* /content/drive/MyDrive/ssh/!ls /content/drive/MyDrive/ssh/```  Test previous setupLet us check that we can see our SSH keys in our mounted google drive.<jupyter_code>from google.colab import drive
drive.mount('/content/drive')

!ls /content/drive/MyDrive/ssh/<jupyter_output>Mounted at /content/drive
id_rsa	id_rsa.pub  known_hosts<jupyter_text>Executing git commands from colab via SSHThe following function lets you securely doing a git command via SSH.It copies the keys from your google drive to the local VM, excecutes the command, then removes the keys.<jupyter_code>!rm -rf pyprobml_utils.py # remove any old copies of this file
!wget https://raw.githubusercontent.com/probml/pyprobml/master/scripts/pyprobml_utils.py  
from google.colab import drive
drive.mount('/content/drive') # must do this before running git_ssh
import pyprobml_utils as pml # import script into namespace<jupyter_output>Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).<jupyter_text>Below we clone the pyprobml repo to this colab VM using out github credentials, so we can later check stuff back in. **This is just an example - you should edit the `reponame`, `username` and `email` variables.***<jupyter_code>!rm -rf pyprobml # remove any old copies of this directory
#!git clone https://github.com/probml/pyprobml.git # clones using wrong credentials
pml.git_ssh("git clone https://github.com/probml/pyprobml.git",
            mail="<EMAIL>", username="probml") # update to use your credentials



reponame = 'pyprobml'
username = 'probml'
email = '<EMAIL>' # update to use your credentials

!rm -rf $reponame # remove any old copies of this directory
cmd = f"git clone https://github.com/{username}/{reponame}.git"
pml.git_ssh(cmd, email=email, username=username)<jupyter_output>executing command via ssh: git clone git@github.com:probml/pyprobml.git<jupyter_text>Let's check that we can see this repo in our local drive.<jupyter_code>!pwd
!ls

!ls /content/$reponame/<jupyter_output>book1  CONTRIBUTING.md	figures  __init__.py  notebooks  scripts
book2  data		images	 LICENSE.txt  README.md<jupyter_text>Now we create a dummy file inside our local copy of this repo, and push it back to the  github (public) version of the repo.<jupyter_code># Make the dummy file in the scripts folder of repo
%cd /content/$reponame
!echo 'this is a test' > scripts/foo.txt

# Add file to the external repo
cmd = "git add scripts; git commit -m 'push from colab'; git push"
pml.git_ssh(cmd, email=email, username=username)<jupyter_output>/content/pyprobml
executing command via ssh: git add scripts; git commit -m 'push from colab'; git push<jupyter_text>We can check that it worked by visiting [this page](https://github.com/probml/pyprobml/blob/master/scripts/foo.txt) on github (note the time stamp on the top right): Finally we clean up our mess.<jupyter_code>%cd /content/$reponame
cmd = "git rm scripts/foo*.txt; git commit -m 'colab cleanup'; git push"
pml.git_ssh(cmd, email=email, username=username, verbose=True)
%cd /content<jupyter_output>/content/pyprobml
executing command via ssh: git rm scripts/foo*.txt; git commit -m 'colab cleanup'; git push
Copying keys from gdrive to local VM
Executing git commands
Cleanup local VM
/content<jupyter_text>Software engineering tools [<NAME> has argued](https://docs.google.com/presentation/d/1n2RlMdmv1p25Xy5thJUhkKGvjtV-dkAIsUXP-AL4ffI/edit) that notebooks are bad for developing complex software, because they encourage creating monolithic notebooks instead of factoring out code into separate, well-tested files.  [<NAME> has responded to Joel's critiques here](https://www.youtube.com/watch?v=9Q6sLbz37gk&feature=youtu.be). In particular, the FastAI organization has created [nbdev](https://github.com/fastai/nbdev) which has various tools that make notebooks more useful.  Avoiding problems with global stateOne of the main drawbacks of colab is that all variables are globally visible, so you may accidently write a function that depends on the current state of the notebook, but which is not passed in as an argument. Such a function may fail if used in a different context.One solution to this is to put most of your code in files, and then have the notebook simply import the code and run it, like you would from the command line. Then you can always run the notebook from scratch, to ensure consistency.Another solution is to use the [localscope](https://localscope.readthedocs.io/en/latest/README.html) package can catch some of these errors.<jupyter_code>!pip install localscope

from localscope import localscope
a = 'hello world'
def myfun():
   print(a) # silently accesses global variable

myfun()
a = 'hello world'
@localscope
def myfun():
  print(a)

myfun()
def myfun2():
  return 42

@localscope
def myfun3():
  return myfun2()

  
@localscope.mfc # allow for global methods, functions, classes
def myfun4():
  return myfun2()

myfun4()<jupyter_output><empty_output><jupyter_text>Factoring out functionality into files stored on githubThe recommended workflow is to  develop your code in the colab in the usual way, and when it is working, to factor out the core code into separate files. You can  edit these files locally in the colab editor, and then push the code to github when ready (see details above). To run functions defined in a local file, just import them. For example, suppose we have created the file /content/pyprobml/scripts/fit_flax.py; we  can use this idiom to run its test suite:```import pyprobml.scripts.fit_flax as ffff.test()```If you make local edits, you want to be sure that you always import the latest version of the file (not a cached version). So you need to use this piece of colab magic first:```%load_ext autoreload%autoreload 2```  File editorsColab has a simple file editor, illustrated below for an example file.This lets you separate your code from the output of your code, as with other IDEs, such as [Jupyter lab](https://jupyterlab.readthedocs.io/en/stable/).<img src="https://github.com/probml/pyprobml/blob/master/book1/intro/figures/colab-file-editor.png?raw=true"> You can click on a class name when holding Ctrl and the source code will open in the file viewer. (h/t [<NAME>dhary's blog](https://amitness.com/2020/06/google-colaboratory-tips/).  VScodeThe default colab file editor is very primitive.See [this article](https://amitness.com/vscode-on-colab/) for how to run VScodefrom inside your Colab browser. Unfortunately this is a bit slow. It is also possible to run VScode locally on your laptop, and have it connect to colab via SSH, but this is more complex (see [this blog post](https://amitness.com/vscode-on-colab/) or [this medium post](https://medium.com/@robertbracco1/configuring-google-colab-like-a-pro-d61c253f75734cf4) for details).  Hardware acceleratorsBy default, Colab runs on a CPU, but you can select GPU or TPU for extra speed, as we show below. To get access to more powerful machines (with faster processors, more memory, and longer idle timeouts), you can subscript to [Colab Pro](https://colab.research.google.com/signup). At the time of writing (Jan 2021), the cost is $10/month (USD). This is a good deal if you use GPUs a lot.   CPUsTo see what devices you have, use this command.<jupyter_code>from tensorflow.python.client import device_lib
device_lib.list_local_devices()
!cat /proc/version
from psutil import cpu_count

print('num cores', cpu_count())

!cat /proc/cpuinfo<jupyter_output>num cores 4
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 79
model name	: Intel(R) Xeon(R) CPU @ 2.20GHz
stepping	: 0
microcode	: 0x1
cpu MHz		: 2200.000
cache size	: 56320 KB
physical id	: 0
siblings	: 4
core id		: 0
cpu cores	: 2
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap xsaveopt arat md_clear arch_capabilities
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa
bogomips	: 4400.00
clflush size	: 64
cache_alignment	: 64
address sizes	: 46 bits ph[...]<jupyter_text>Memory<jupyter_code>from psutil import virtual_memory
ram_gb = virtual_memory().total / 1e9
print('RAM (GB)', ram_gb)


!cat /proc/meminfo<jupyter_output>MemTotal:       26751776 kB
MemFree:        23653276 kB
MemAvailable:   25773356 kB
Buffers:          109276 kB
Cached:          2230616 kB
SwapCached:            0 kB
Active:           756592 kB
Inactive:        1980036 kB
Active(anon):     363548 kB
Inactive(anon):      416 kB
Active(file):     393044 kB
Inactive(file):  1979620 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:               392 kB
Writeback:             0 kB
AnonPages:        396824 kB
Mapped:           212400 kB
Shmem:              1032 kB
Slab:             201364 kB
SReclaimable:     140252 kB
SUnreclaim:        61112 kB
KernelStack:        4528 kB
PageTables:         5336 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    13375888 kB
Committed_AS:    3257684 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
Percpu:             2096 kB
AnonHugePages:   [...]<jupyter_text>GPUsIf you select the 'Runtime' menu at top left, and then select 'Change runtime type' and then select 'GPU', you can get free access to a GPU. <img src="https://github.com/probml/pyprobml/blob/master/book1/intro/figures/colab-change-runtime.png?raw=true" height=300><img src="https://github.com/probml/pyprobml/blob/master/book1/intro/figures/colab-select-gpu.png?raw=true" height=200> To see what kind of GPU you are using, see below.<jupyter_code>gpu_info = !nvidia-smi
gpu_info = '\n'.join(gpu_info)
print(gpu_info)
!grep Model: /proc/driver/nvidia/gpus/*/information | awk '{$1="";print$0}'<jupyter_output>Tesla P100-PCIE-16GB<jupyter_text>Using Julia in colabSee [this colab](https://colab.research.google.com/github/ageron/julia_notebooks/blob/master/Julia_Colab_Notebook_Template.ipynb)<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10923340680871908, 'fraction_numerical': 0.018788705783562506, 'mean_word_length': 4.458747135217723, 'pattern_counts': {'":': 0, '<': 128, '<?xml version=': 0, '>': 138, 'https://': 44, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '35', 'dir': 'jupyter-structured-clean-dedup', 'id': '127530', 'license': 'MIT', 'n_tokens_mistral': 9723, 'n_tokens_neox': 9165, 'n_words': 3103, 'path': 'book1/supplements/colab_intro.ipynb', 'repo_name': 'nappaillav/pyprobml', 'size': '28619'}