Skip to content

Commit 5598012

Browse files
authored
Add additional platform page for third-party vendor (#2072)
This PR adds a new page for users to search for guidelines for more PyTorch backends through the official website.
1 parent 788e28a commit 5598012

9 files changed

Lines changed: 849 additions & 0 deletions

.github/workflows/update-quick-start-module.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@ on:
77
paths:
88
- .github/workflows/update-quick-start-module.yml
99
- scripts/gen_quick_start_module.py
10+
- scripts/gen_additional_platforms.py
1011
- _includes/quick-start-module.js
1112
- _includes/quick_start_local.html
13+
- _additional_platforms/*.json
14+
- _get_started/additional_platforms/*.md
1215
push:
1316
branches:
1417
site
1518
paths:
1619
- .github/workflows/update-quick-start-module.yml
1720
- scripts/gen_quick_start_module.py
21+
- scripts/gen_additional_platforms.py
1822
- _includes/quick-start-module.js
1923
- _includes/quick_start_local.html
24+
- _additional_platforms/*.json
25+
- _get_started/additional_platforms/*.md
2026
workflow_dispatch:
2127

2228
jobs:
@@ -116,3 +122,20 @@ jobs:
116122
body: >
117123
This PR is auto-generated. It updates Getting Started page
118124
labels: automated pr
125+
126+
update-additional-platform:
127+
runs-on: "ubuntu-latest"
128+
environment: pytorchbot-env
129+
steps:
130+
- name: Checkout pytorch.github.io
131+
uses: actions/checkout@v2
132+
- name: Setup Python
133+
uses: actions/setup-python@v2
134+
with:
135+
python-version: 3.9
136+
architecture: x64
137+
- name: Generate quick-start-additional-platforms.js
138+
shell: bash
139+
run: |
140+
set -ex
141+
python3 ./scripts/gen_additional_platforms.py

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,4 @@ PyTorch repo [README.md](https://github.com/pytorch/pytorch/blob/master/README.m
9292
* Information about contributing to PyTorch Tutorials can be found in the
9393
tutorials [README.md](https://github.com/pytorch/tutorials/blob/master/README.md).
9494
* Additional contribution information can be found in [PyTorch CONTRIBUTING.md](https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md).
95+
* To add additional accelerators to pytorch.org, please refer to [additional_platforms.md](additional_platforms.md).
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
layout: get_started
3+
title: Additional Platforms
4+
permalink: /get-started/additional-platforms/
5+
background-class: get-started-background
6+
body-class: get-started
7+
order: 1
8+
published: true
9+
get-started-additional: true
10+
---
11+
12+
<div class="container-fluid quick-start-module quick-starts">
13+
<div class="row">
14+
<div class="col-md-12">
15+
{% include quick_start_additional_platforms.html %}
16+
</div>
17+
</div>
18+
</div>
19+
20+
---
21+
<div id="additional-platforms-installation">
22+
<!-- Platform content divs will be dynamically created by JavaScript -->
23+
</div>
24+
25+
<script page-id="get-started-additional-platforms" src="{{ site.baseurl }}/assets/menu-tab-selection.js"></script>
26+
<script src="{{ site.baseurl }}/assets/quick-start-additional-platforms.js"></script>
27+
<script src="{{ site.baseurl }}/assets/get-started-sidebar.js"></script>

_get_started/get-started-locally.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ redirect_from: "/get-started/"
2020
</div>
2121
</div>
2222

23+
<p><i>Could not find the right platform for your hardware?</i> See the <a href="{{ site.baseurl }}/get-started/additional-platforms/">PyTorch Additional Platforms</a> page.</p>
24+
2325
---
2426

2527
{% capture mac %}
Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
// =====================================================
2+
// Additional Platforms Quick Start Module
3+
// =====================================================
4+
5+
// Platform data loaded from JSON files (generated by gen_additional_platforms.py)
6+
var ecosystemPlatformData = {{ platformData }};
7+
8+
// HTML content loaded from _get_started/additional_platforms/ directory
9+
// (pre-converted by Python script with syntax highlighting)
10+
var ecosystemHtmlContent = {{ markdownContent }};
11+
12+
// Get platform IDs from loaded data
13+
var ecosystemPlatformIds = Object.keys(ecosystemPlatformData);
14+
15+
// Ecosystem platform selections - simplified (no pm, no version)
16+
var ecosystemOpts = {
17+
build: 'stable',
18+
os: 'linux',
19+
platform: null
20+
};
21+
22+
// Initialize additional platforms when document is ready
23+
$(function() {
24+
initPlatformContentContainer();
25+
initAdditionalPlatforms();
26+
initAdditionalPlatformButtons();
27+
updatePlatformButtonStates();
28+
updateBuildButtonStates();
29+
syncComputePlatformHeight();
30+
initPlatformContentDisplay();
31+
});
32+
33+
// Initialize platform content container - dynamically create divs for each platform
34+
function initPlatformContentContainer() {
35+
var container = $('#additional-platforms-installation');
36+
if (!container.length) return;
37+
38+
// Clear any existing static content
39+
container.empty();
40+
41+
// Create platform content divs dynamically based on HTML content
42+
ecosystemPlatformIds.forEach(function(platformId) {
43+
if (ecosystemHtmlContent[platformId]) {
44+
var contentDiv = $('<div class="platform-content ' + platformId + '"></div>');
45+
// HTML content is already pre-converted with syntax highlighting
46+
contentDiv.html(ecosystemHtmlContent[platformId]);
47+
container.append(contentDiv);
48+
}
49+
});
50+
}
51+
52+
// Note: Markdown is pre-converted to HTML by Python script (gen_additional_platforms.py)
53+
// using markdown library with codehilite extension for syntax highlighting.
54+
// No need for client-side markdown parsing.
55+
56+
// Initialize platform content display - hide all initially
57+
function initPlatformContentDisplay() {
58+
$('#additional-platforms-installation .platform-content').hide();
59+
}
60+
61+
// Sync left heading height with right compute platform buttons height
62+
function syncComputePlatformHeight() {
63+
var rightHeight = $('.compute-platform').outerHeight();
64+
if (rightHeight > 0) {
65+
$('.compute-platform-heading').css('min-height', rightHeight + 'px');
66+
}
67+
}
68+
69+
// Populate compute platform buttons
70+
function initAdditionalPlatformButtons() {
71+
var platformRow = $('.compute-platform');
72+
if (!platformRow.length) return;
73+
74+
// Generate platform buttons
75+
ecosystemPlatformIds.forEach(function(platformId) {
76+
var platform = ecosystemPlatformData[platformId];
77+
if (!platform) return;
78+
var displayName = platform.name;
79+
var btn = $('<div class="col-md-3 option block" id="' + platformId + '"><div class="option-text">' + displayName + '</div></div>');
80+
platformRow.append(btn);
81+
});
82+
83+
// Sync height after buttons are generated
84+
syncComputePlatformHeight();
85+
86+
// Bind platform button click
87+
$('.compute-platform > .option').on('click', function() {
88+
var platformId = this.id;
89+
var platform = ecosystemPlatformData[platformId];
90+
if (!platform) return;
91+
92+
// Check if supported on current OS
93+
var supportedOS = getSupportedOS(platformId);
94+
if (!supportedOS.includes(ecosystemOpts.os)) {
95+
$('#command').html('<i>' + platform.name + ' is not supported on ' + ecosystemOpts.os + '</i>');
96+
return;
97+
}
98+
99+
// Select this platform
100+
$('.compute-platform > .option').removeClass('selected');
101+
$(this).addClass('selected');
102+
ecosystemOpts.platform = platformId;
103+
104+
updateBuildButtonStates();
105+
updateEcosystemCommand();
106+
updatePlatformContentDisplay();
107+
});
108+
}
109+
110+
// Get supported OS list from platform data structure
111+
function getSupportedOS(platformId) {
112+
var platform = ecosystemPlatformData[platformId];
113+
if (!platform) return [];
114+
115+
var osSet = new Set();
116+
['stable', 'preview'].forEach(function(build) {
117+
if (platform[build]) {
118+
Object.keys(platform[build]).forEach(function(os) {
119+
osSet.add(os);
120+
});
121+
}
122+
});
123+
return Array.from(osSet);
124+
}
125+
126+
// Get supported build list for a platform
127+
function getSupportedBuilds(platformId) {
128+
var platform = ecosystemPlatformData[platformId];
129+
if (!platform) return [];
130+
var builds = [];
131+
if (platform.stable) builds.push('stable');
132+
if (platform.preview) builds.push('preview');
133+
return builds;
134+
}
135+
136+
// Update platform button states (disabled/enabled) based on OS
137+
function updatePlatformButtonStates() {
138+
$('.compute-platform > .option').each(function() {
139+
var platformId = this.id;
140+
if (!platformId) return;
141+
142+
var supportedOS = getSupportedOS(platformId);
143+
var isSupported = supportedOS.includes(ecosystemOpts.os);
144+
145+
if (isSupported) {
146+
$(this).css('text-decoration', '');
147+
} else {
148+
$(this).css('text-decoration', 'line-through');
149+
}
150+
});
151+
152+
// If currently selected platform is not supported on new OS, deselect it
153+
if (ecosystemOpts.platform) {
154+
var supportedOS = getSupportedOS(ecosystemOpts.platform);
155+
if (!supportedOS.includes(ecosystemOpts.os)) {
156+
ecosystemOpts.platform = null;
157+
$('.compute-platform > .option').removeClass('selected');
158+
$('#command').html('Select a compute platform to see the installation command.');
159+
updatePlatformContentDisplay();
160+
}
161+
}
162+
}
163+
164+
// Update build button states (disabled/enabled) based on selected platform
165+
function updateBuildButtonStates() {
166+
$('.pytorch-build > .option').each(function() {
167+
var buildId = this.id;
168+
if (!buildId) return;
169+
170+
if (!ecosystemOpts.platform) {
171+
// No platform selected - show all builds as available
172+
$(this).css('text-decoration', '');
173+
return;
174+
}
175+
176+
var supportedBuilds = getSupportedBuilds(ecosystemOpts.platform);
177+
var isSupported = supportedBuilds.includes(buildId);
178+
179+
if (isSupported) {
180+
$(this).css('text-decoration', '');
181+
} else {
182+
$(this).css('text-decoration', 'line-through');
183+
}
184+
});
185+
186+
// If currently selected build is not supported by the platform, auto-switch to a supported build
187+
if (ecosystemOpts.platform) {
188+
var supportedBuilds = getSupportedBuilds(ecosystemOpts.platform);
189+
if (!supportedBuilds.includes(ecosystemOpts.build)) {
190+
// Switch to the first supported build
191+
if (supportedBuilds.length > 0) {
192+
ecosystemOpts.build = supportedBuilds[0];
193+
$('.pytorch-build > .option').removeClass('selected');
194+
$('.pytorch-build > .option#' + ecosystemOpts.build).addClass('selected');
195+
}
196+
}
197+
}
198+
}
199+
200+
// Update platform content display based on selected platform
201+
function updatePlatformContentDisplay() {
202+
// Hide all platform content first
203+
$('#additional-platforms-installation .platform-content').hide();
204+
205+
// Show selected platform content
206+
if (ecosystemOpts.platform) {
207+
$('#additional-platforms-installation .platform-content.' + ecosystemOpts.platform).show();
208+
}
209+
}
210+
211+
// Initialize all click events for build/os blocks
212+
function initAdditionalPlatforms() {
213+
// PyTorch Build - prevent selecting unsupported builds
214+
$('.pytorch-build > .option').on('click', function() {
215+
var buildId = this.id;
216+
217+
// Check if this build is supported by the selected platform
218+
if (ecosystemOpts.platform) {
219+
var supportedBuilds = getSupportedBuilds(ecosystemOpts.platform);
220+
if (!supportedBuilds.includes(buildId)) {
221+
// Don't allow selecting unsupported build
222+
return;
223+
}
224+
}
225+
226+
$('.pytorch-build > .option').removeClass('selected');
227+
$(this).addClass('selected');
228+
ecosystemOpts.build = buildId;
229+
updateEcosystemCommand();
230+
});
231+
232+
// OS - with platform support check
233+
$('.os-ecosystem > .option').on('click', function() {
234+
$('.os-ecosystem > .option').removeClass('selected');
235+
$(this).addClass('selected');
236+
ecosystemOpts.os = this.id;
237+
238+
updatePlatformButtonStates();
239+
updateBuildButtonStates();
240+
updateEcosystemCommand();
241+
});
242+
}
243+
244+
// Update ecosystem command based on selections - simplified
245+
function updateEcosystemCommand() {
246+
if (!ecosystemOpts.platform) {
247+
$('#command').html('Select a compute platform to see the installation command.');
248+
$('#support-channel').html('Select a compute platform to see the support channel.');
249+
return;
250+
}
251+
252+
var platform = ecosystemPlatformData[ecosystemOpts.platform];
253+
if (!platform) {
254+
$('#command').html('Loading platform data...');
255+
$('#support-channel').html('Loading platform data...');
256+
return;
257+
}
258+
259+
// Check if OS is supported
260+
var supportedOS = getSupportedOS(ecosystemOpts.platform);
261+
if (!supportedOS.includes(ecosystemOpts.os)) {
262+
$('#command').html('<i>' + platform.name + ' is not supported on ' + ecosystemOpts.os + '</i>');
263+
$('#support-channel').html('<i>Select a supported platform to see the support channel.</i>');
264+
return;
265+
}
266+
267+
// Get command directly from platform[build][os]
268+
try {
269+
var buildData = platform[ecosystemOpts.build];
270+
if (!buildData || !buildData[ecosystemOpts.os]) {
271+
$('#command').html('<i>Configuration not available for this combination</i>');
272+
$('#support-channel').html('<i>Select a valid combination to see the support channel.</i>');
273+
return;
274+
}
275+
276+
var cmd = buildData[ecosystemOpts.os];
277+
278+
if (cmd) {
279+
$('#command').html('<pre>' + cmd + '</pre>');
280+
} else {
281+
$('#command').html('<i>Configuration not available for this combination</i>');
282+
}
283+
284+
// Update support channel
285+
if (platform.support_channel) {
286+
$('#support-channel').html('<a href="' + platform.support_channel + '" target="_blank">' + platform.support_channel + '</a>');
287+
} else {
288+
$('#support-channel').html('<i>No support channel available for this platform.</i>');
289+
}
290+
} catch (e) {
291+
$('#command').html('<i>Configuration not available for this combination</i>');
292+
$('#support-channel').html('<i>Configuration not available</i>');
293+
}
294+
}

0 commit comments

Comments
 (0)