What is the PyTorch installation interactive grid called and how do I make my own?

I’ve really enjoyed using the interactive grid selection on the PyTorch installation page, and for a while I’ve wanted to do something similar to this on a separate project.

I’ve been searching online and playing around using HTML “inspect”. From what I can tell, each of the buttons are contained in row-s inside of a container. When one of the buttons is clicked, the following three network events (Javascript functions?) are triggered:


analytics.js
fbevents.js
analytics.js

Taking a look at the payload for the fbevents.js event, it seems like a GET request that has the cd[target]: corresponding to the button that was clicked and it’s row heading (e.g., cd[target]: Your OS: Linux).

id: 243028289693773
ev: Quick Start Module - Local Install
dl: https://pytorch.org/
rl: https://www.google.com/
if: false
ts: 1677705739419
cd[target]: Your OS: Linux
sw: 1397
sh: 786
v: 2.9.97
r: stable
ec: 4
o: 30
fbp: fb.1.1675910707543.1834767952
it: 1677705336651
coo: false
rqm: GET

As the buttons are clicked, the string in the command-container is changed:

<div class="row">
  <div class="col-md-3 headings">
    <div class="col-md-12 title-block">
      <div class="option-text">PyTorch Build</div>
    </div>
    <div class="col-md-12 title-block">
      <div class="option-text os-text">Your OS</div>
    </div>
    <div class="col-md-12 title-block">
      <div class="option-text">Package</div>
    </div>
    <div class="col-md-12 title-block">
      <div class="option-text">Language</div>
    </div>
    <div class="col-md-12 title-block">
      <div class="option-text">Compute Platform</div>
    </div>
    <div class="col-md-12 title-block command-block">
      <div class="option-text command-text">Run this Command:</div>
    </div>
  </div>

  <div class="col-md-9">
    <div class="row ptbuild">
      <div class="col-md-12 title-block mobile-heading">
        <div class="option-text">PyTorch Build</div>
      </div>
      <div class="col-md-6 option block version" id="stable">
        <div class="option-text">Stable (1.13.1)</div>
      </div>
      <div class="col-md-6 option block version selected" id="preview">
        <div class="option-text">Preview (Nightly)</div>
      </div>
    </div>
    <div class="row os">
      <div class="col-md-12 title-block mobile-heading">
        <div class="option-text">Your OS</div>
      </div>
      <div class="col-md-4 option block selected" id="linux">
        <div class="option-text">Linux</div>
      </div>
      <div class="col-md-4 option block" id="macos">
        <div class="option-text">Mac</div>
      </div>
      <div class="col-md-4 option block" id="windows">
        <div class="option-text">Windows</div>
      </div>
    </div>
    <div class="row package">
      <div class="col-md-12 title-block mobile-heading">
        <div class="option-text">Package</div>
      </div>
      <div class="col-md-3 option block selected" id="conda">
        <div class="option-text">Conda</div>
      </div>
      <div class="col-md-3 option block" id="pip">
        <div class="option-text">Pip</div>
      </div>
      <div class="col-md-3 option block" id="libtorch">
        <div class="option-text">LibTorch</div>
      </div>
      <div class="col-md-3 option block" id="source">
        <div class="option-text">Source</div>
      </div>
    </div>
    <div class="row language">
      <div class="col-md-12 title-block mobile-heading">
        <div class="option-text">Language</div>
      </div>
      <div class="col-md-6 option block version selected" id="python">
        <div class="option-text">Python</div>
      </div>
      <div class="col-md-6 option block" id="cplusplus">
        <div class="option-text">C++ / Java</div>
      </div>
    </div>
    <div class="row cuda">
      <div class="col-md-12 title-block mobile-heading">
        <div class="option-text">Compute Platform</div>
      </div>
      <div class="col-md-3 option block version selected" id="cuda.x">
        <div class="option-text">CUDA 11.7</div>
      </div>
      <div class="col-md-3 option block version" id="cuda.y">
        <div class="option-text">CUDA 11.8</div>
      </div>
      <div class="col-md-3 option block version" id="rocm5.x" style="">
        <div class="option-text">ROCm 5.4.2</div>
      </div>
      <div class="col-md-3 option block version" id="accnone">
        <div class="option-text">CPU</div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-12 title-block command-mobile-heading">
        <div class="option-text">Run this Command:</div>
      </div>
      <div class="command-container">
        <div class="col-md-12" id="command"><pre>conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch-nightly -c nvidia</pre></div>
      </div>
    </div>
  </div>
</div>

i.e.,

      <div class="command-container">
        <div class="col-md-12" id="command"><pre>conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch-nightly -c nvidia</pre></div>
      </div>

I had trouble finding where the PyTorch website gets generated (e.g., looking through the .ci and .github folders at https://github.com/pytorch/pytorch, assuming that code for that is publicly available).

Any thoughts/suggestions on how to get this implemented or alternatives? If someone has the appropriate language to describe this or some references, it would help a lot.

EDIT: Some extra resources during my search:

I’m not a web developer and just took one course while I was at the university, so I won’t be able to exactly tell you which (new) JS framework was used, but this seems to be the “Get Started” page, which then points to some assets.
The quick-start-module.js seems to contain the JS code for the actual menu.

From the README of the repo it seems that Jekyll and Bootstrap were used.

1 Like

@ptrblck This is a great starting point for me. Thank you! Searching through the repo, I was also able to find some GitHub actions workflows for updating and validating the quick start module which calls scripts/gen_quick_start_module.py. Taking a look at the docstring there:

Generates quick start module for Start Locally | PyTorch page
If called from update-quick-start-module.yml workflow (--autogenerate parameter set)
Will output new quick-start-module.js, and new published_version.json file
based on the current release matrix.
If called standalone will generate quick-start-module.js from existing
published_version.json file

It seems that I may not need to deal with Javascript directly.

The first step might be fork the repo, follow the setup instructions, run the website locally, and gradually piece out / adapt the functionality to my other use-case.

This looks lengthy, but doable to me!

1 Like

A friend got back to me with the following:

If you’re looking for some place to start maybe look into Bootstrap styling. I asked ChatGPT for a mockup of radio buttons being used in forms to give the user something they could copy to clipboard

I think what I will probably do is take a “sculpting” approach where I chisel away until I get down to its core functionality. This might be tough if everything’s a spiderweb, but I think it would be pretty useful to get down to a MWE for this (including both the interface and the unit tests under the hood that lead to certain configurations being crossed out if they don’t pass).

This post goes through the GitHub workflows and install matrix generation step, dives into the Javascript template, and concludes with the HTML template.

GitHub Workflows and Install Matrix Generation

On the PyTorch side (rather than the PyTorch website gh repo), this script pytorch/.github/scripts/generate_binary_build_matrix.py at 66d3729388b6dc2ae257d984765814a5d42e9060 · pytorch/pytorch · GitHub seems to have an options lists, e.g.:

This creates .yml workflow files via:

(Aside: links related to `generate_ci_workflows.py`: https://github.com/pytorch/pytorch/issues/74480 and https://github.com/search?q=repo%3Apytorch%2Fpytorch%20generate_ci_workflows.py&type=code)

On GitHub - pytorch/pytorch.github.io: The website for PyTorch (rather than GitHub - pytorch/pytorch: Tensors and Dynamic neural networks in Python with strong GPU acceleration), it runs individually for MacOS, Linux, and Windows (both nightly and release versions) via GitHub actions:

Going back to how the javascript gets generated, I see:

which is defined at:

My takeaway is that it comes back to pytorch.github.io/assets/quick-start-module.js at site · pytorch/pytorch.github.io · GitHub (linked above by @ptrblck), where the template file for this is stored at:

I realize I do actually need to understand the Javascript here in order to adapt it. In other words, the JS code isn’t autogenerated, it just gets slightly modified from the template (_includes/quick-start-module.js directory, not assets/quick-start-module.js directory) linked above:

The diff between these two files is interesting:

and (cropped):

Javascript

Taking a closer look at the JS file, the variables and click functions for each of the rows in the installation grid are given in:

The functions are wrappers to selectedOption():

Importantly, this depends on commandMessage():

given in:

where var object = {"preview,pip,linux,accnone,python": "pip3 install --pre torch ...", ...} was modified from the template file line var object = {{ installMatrix }}; as described in the reply preceding this one.

Note the form of the line:
{"<option1>,<option2>,<option3>,<option4>,<option5>": "<install command>", ...}

I think it’s also worth mentioning disableUnsupportedPlatforms(os) which does the strike-through:

HTML

In terms of the HTML templates located in the _includes directory:

pulls from:

To complete the circle, the HTML file uses the Javascript file in:

I want to add my agreement that the install command generating widget in the PyTorch site is a beautiful piece of UI. It is intuitive and simplifies the CUDA install massively. A huge lesson for NVIDIA here. I am struck by the widget every time I see it. Thank you.