Getting Started¶

Wellcome to the Hidet tutorial!

This tutorial will show you

  • How to use Hidet to optimize the performance of a model
  • How to define a model with Hidet's API
  • How to add a new operator to Hidet
  • How to write tensor programs with Hidet Script

More documentation can be found at Hidet's website.

1. Run the Tutorial as a Jupyter Notebook¶

If you wish to play along with the tutorial notebook, we recommend that you launch a jupyter notebook.

# create a python virtual env
virtualenv hidet-tutorial && source hidet-tutorial/bin/activate

# install jupyter notebook
pip install notebook

# install dependency of this tutorial
pip install torch torchaudio torchvision wurlitzer Pygments

# install hidet
pip install hidet

# launch a jupyter notebook 
jupyter notebook --port 8888 --ip 0.0.0.0

1.1 For the server provided by workshop¶

If you are using a VM provided by the workshop, simply visit <ip of the machine>:8888

You will be asked to provide a token, look for the token in the output of the jupyter command above.

1.2 For your own server¶

If you are using you own remote CUDA capable machine, perform a port-forwarding

ssh -NL 8888:localhost:8888 <user>@<remote>

and open http://127.0.0.1:8888

2. Open the notebook¶

You should have already cloned the GitHub repository for this tutorial (https://github.com/CentML/asplos23-tutorial). You can find two subdirectories that contains the notebooks:

  • Hidet usage tutorial: asplos23-tutorial/hidet_tutorials_ipynb/
  • Hidet script tutorial: asplos23-tutorial/hidet_script_tutorials_ipynb/

To check if Hidet is installed and functions correctly, you can run the following jupyter cell:

In [1]:
import hidet
print(hidet.randn([3, 4]) + 1)
Compiling cpu task adds(x=float32[3, 4])...
Tensor(shape=(3, 4), dtype='float32', device='cpu')
[[2.4308946  1.0857943  0.94579965 0.20885205]
 [0.43885875 0.2745815  1.453223   2.7053485 ]
 [0.5086057  0.3385288  1.5116855  2.1649857 ]]