Skip to content

Conversation

r4victor
Copy link
Collaborator

Part of #2372

The PR adds a scripts/add_backend.py script to generate all the necessary files and classes for a new backend and updates the backend guide to use it.

@r4victor r4victor requested review from jvstme and un-def March 11, 2025 11:23
Copy link
Collaborator

@jvstme jvstme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 26 to 29
loader=jinja2.PackageLoader(
package_name="dstack",
package_path="_internal/core/backends/template",
),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) _internal/core/backends/template/*.jinja2 is not actually included in the package, so this won't work in the general case. It does work for me when dstack is installed in editable mode, but this is probably an implementation detail of pip, so I wouldn't rely on it.

I'd suggest using jinja2.FileSystemLoader instead.

Comment on lines +22 to +23
# TODO: Add all supported regions and default regions
REGIONS = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded regions are not needed for most backends, so I wouldn't include this in the template.

I guess they used to be needed for interactive setup, but now they are only needed for backends with custom-built VM images that are not available in all regions. For other backends, hardcoded regions are rather harmful, as they prevent users from using newly added regions

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regions don't need to be hardcoded but they need to be validated, and hardcoding them seems to be the best option for most GPU clouds (have a few regions, don't add new regions often, unlikely to have an API to get all the regions).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, feel free to adjust the template on regions.

Comment on lines +44 to +45
# If the provider is added to gpuhunt, you'd typically get offers
# using `get_catalog_offers()` and extend them with availability info.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) Consider adding a sample call to get_catalog_offers, as contributors can forget to pass important arguments, such as locations or configurable_disk_size.

offers = get_catalog_offers(
    backend=BackendType.{{ backend_name|upper }},
    locations=self.config.regions or None,
    requirements=requirements,
    configurable_disk_size=...,  # TODO: set in case of boot volume size limits
)

@r4victor r4victor merged commit 9ccae54 into master Mar 12, 2025
24 checks passed
@r4victor r4victor deleted the issue_2372_backend_template branch March 12, 2025 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants