Skip to content

Commit

Permalink
[core] Merge upstream (#5)
Browse files Browse the repository at this point in the history
* [LLM] Update qwen examples (skypilot-org#3957)

* update qwen examples

* Fix misalign

* Qwen 2.5 support (skypilot-org#3959)

* Update qwen example for 2.5 release

* Add support for qwen 2.5 example

* Qwen 2.5 k8s (skypilot-org#3960)

* Update qwen example for 2.5 release

* Add support for qwen 2.5 example

* add kubernetes

* Integrating the Yi series models (skypilot-org#3958)

* Add files via upload

* Update and rename qwen2-7b.yaml to yi15-6b.yaml

* Add files via upload

* Update yi15-9b.yaml

* Update yi15-34b.yaml

* Update yi15-6b.yaml

* Add files via upload

* Update yicoder-1_5b.yaml

* Update yicoder-9b.yaml

* Add files via upload

* Update yi15-34b.yaml

* Update yi15-6b.yaml

* Update yi15-9b.yaml

* Update yicoder-1_5b.yaml

* Update yicoder-9b.yaml

* [Test] Fix Smoke Test `test-skyserve-fast-update` (skypilot-org#3956)

* init

* add newline

* [LLM] Add Qwen2-VL multimodal example (skypilot-org#3961)

Add multimodal example

* Update README.md  (skypilot-org#3969)

* Add files via upload

* Update and rename qwen2-7b.yaml to yi15-6b.yaml

* Add files via upload

* Update yi15-9b.yaml

* Update yi15-34b.yaml

* Update yi15-6b.yaml

* Add files via upload

* Update yicoder-1_5b.yaml

* Update yicoder-9b.yaml

* Add files via upload

* Update yi15-34b.yaml

* Update yi15-6b.yaml

* Update yi15-9b.yaml

* Update yicoder-1_5b.yaml

* Update yicoder-9b.yaml

* Update README.md

* [Core] Admin policy enforcement plugin (skypilot-org#3966)

* support policy hook

* test task labels

* Add test for policy that sets labels

* Fix comment

* format

* use -e to make test related files visible

* Add config.rst

* Fix test

* fix config rst

* Apply policy to service

* add policy for serving

* Add docs

* fix

* format

* Update interface

* fix

* Fix

* fix

* Fix test config

* Fix mutated config

* fix

* Add policy doc

* rename

* minor

* Add additional arguments for autostop

* fix mypy

* format

* rejected message

* format

* Update sky/utils/policy_utils.py

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* Update sky/utils/policy_utils.py

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* Fix

* Update examples/admin_policy/example_policy/example_policy/__init__.py

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* Update docs/source/reference/config.rst

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* Address comments

* format

* changes in examples

* Fix enforce autostop

* Fix autostop enforcement

* fix test

* Update docs/source/cloud-setup/policy.rst

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* Update sky/admin_policy.py

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* Update sky/admin_policy.py

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* wip

* Update docs/source/cloud-setup/policy.rst

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* Update docs/source/cloud-setup/policy.rst

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* Update docs/source/cloud-setup/policy.rst

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* fix

* fix

* fix

* Use sky.status for autostop

* update policy

* Update docs/source/cloud-setup/policy.rst

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* fix policy.rst

* Add comment

* Fix logging

* fix CI

* Update docs/source/cloud-setup/policy.rst

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* Use sphnix inline code

* Add comment

* fix skypilot config file mounts for jobs and serve

---------

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* [k8s] Autodown Serve controller on Kubernetes (skypilot-org#3984)

* Add autodown for skyserve on k8s

* lint

* [Tests] Add missing changes from skypilot-org#3966 for fast service update test (skypilot-org#3976)

Use wget instead of git clone for faster downloading

* [Paperspace] add A4000, P4000, GPU+ (skypilot-org#3991)

add A4000, P4000, GPU+

* [Docs] Fix highlighting in code block (skypilot-org#3994)

Fix highlighting in code block

Fixes skypilot-org#3993

* [LLM] Llama 3.2 guide (skypilot-org#3990)

* Add llama 3.2 example

* update

* length

* fix

* update

* update cpus limit

* Use 11B instead for better performance

* update

* update

* Add link

* Fix reference

* Fix vllm version

* Update llm/llama-3_2/README.md

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* Update llm/llama-3_2/README.md

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* Update llm/llama-3_2/README.md

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* Update llm/llama-3_2/README.md

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* Fix title

* news

* no need to pin transformers

* remove cover photo for now

---------

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* [k8s] Add cluster attributes(autodown, idle-minutes-to-autostop) as annotations to the pod (skypilot-org#3870)

* add autodown annotations to the k8s pod

* revert kubernetes ray template

* revert backend_utils from invasive approach

* nit

* revert from invasive approaches

* revert

* updated approach

* nit

* nit

* Use constant to represent idle_minutes_to_autostop for cancellation

* revert using constants for cancel

* nit

* nit

* add smoke tests

* Update sky/provision/kubernetes/utils.py

Co-authored-by: Romil Bhardwaj <romil.bhardwaj@gmail.com>

* fix comments

* nit

* remove loops and annotate one by one

* format

* update with autodown annotation with context

* format

---------

Co-authored-by: Romil Bhardwaj <romil.bhardwaj@gmail.com>

* [Examples] Add airflow example (skypilot-org#3982)

* Airflow example

* Airflow example

* Airflow example

* Airflow example

* wip

* Update airflow examples

* Update airflow examples

* Update airflow examples

* Add to readme

* Add to readme

* Add to readme

* lint

* updates

* less salesy

* comments

* comments

* comments

* [UX] default to minimal logging (no module/line number/timestamp). (skypilot-org#3980)

* [UX] default to minimal logging (no module/line number/timestamp).

* Fix mypy.

* Fix typing

* Update sky/utils/env_options.py

Co-authored-by: Tian Xia <cblmemo@gmail.com>

* Update sky/utils/env_options.py

Co-authored-by: Tian Xia <cblmemo@gmail.com>

* Account for debug flag.

* Remove prefixes from docs.

---------

Co-authored-by: Tian Xia <cblmemo@gmail.com>

* Revert "[UX] default to minimal logging (no module/line number/timestamp)." (skypilot-org#4003)

Revert "[UX] default to minimal logging (no module/line number/timestamp). (#…"

This reverts commit b96a5b4.

* [Docs] Clarify k8s private registry usage in docs (skypilot-org#3998)

* Clarify k8s private registry auth in docs.

* comments

* [Docs] Various polishing. (skypilot-org#4002)

* [Docs] Various polishing.

* update

* Reword.

* lint

---------

Co-authored-by: Zhanghao Wu <zhanghao.wu@outlook.com>
Co-authored-by: Haijian Wang <130898843+Haijian06@users.noreply.github.com>
Co-authored-by: Tian Xia <cblmemo@gmail.com>
Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>
Co-authored-by: Romil Bhardwaj <romil.bhardwaj@berkeley.edu>
Co-authored-by: Andy Lee <andylizf@outlook.com>
Co-authored-by: landscapepainter <34902420+landscapepainter@users.noreply.github.com>
Co-authored-by: Romil Bhardwaj <romil.bhardwaj@gmail.com>
  • Loading branch information
9 people authored Sep 27, 2024
1 parent 980b7ac commit 99a9260
Show file tree
Hide file tree
Showing 74 changed files with 2,775 additions and 281 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ".[all]"
pip install -e ".[all]"
pip install pytest pytest-xdist pytest-env>=0.6 memory-profiler==0.61.0
- name: Run tests with pytest
Expand Down
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,27 @@ This repository is a fork of the [original Skypilot](https://github.com/skypilot

----
:fire: *News* :fire:
- [Sep, 2024] Run and deploy [Pixtral](./llm/pixtral), the first open-source multimodal model from Mistral AI.
- [Jul, 2024] [Finetune](./llm/llama-3_1-finetuning/) and [serve](./llm/llama-3_1/) **Llama 3.1** on your infra
- [Sep, 2024] Point, Launch and Serve **Llama 3.2** on on Kubernetes or Any Cloud: [**example**](./llm/llama-3_2/)
- [Sep, 2024] Run and deploy [**Pixtral**](./llm/pixtral), the first open-source multimodal model from Mistral AI.
- [Jul, 2024] [**Finetune**](./llm/llama-3_1-finetuning/) and [**serve**](./llm/llama-3_1/) **Llama 3.1** on your infra
- [Jun, 2024] Reproduce **GPT** with [llm.c](https://github.com/karpathy/llm.c/discussions/481) on any cloud: [**guide**](./llm/gpt-2/)
- [Apr, 2024] Serve and finetune [**Llama 3**](https://skypilot.readthedocs.io/en/latest/gallery/llms/llama-3.html) on any cloud or Kubernetes: [**example**](./llm/llama-3/)
- [Apr, 2024] Serve [**Qwen-110B**](https://qwenlm.github.io/blog/qwen1.5-110b/) on your infra: [**example**](./llm/qwen/)
- [Apr, 2024] Using [**Ollama**](https://github.com/ollama/ollama) to deploy quantized LLMs on CPUs and GPUs: [**example**](./llm/ollama/)
- [Feb, 2024] Deploying and scaling [**Gemma**](https://blog.google/technology/developers/gemma-open-models/) with SkyServe: [**example**](./llm/gemma/)
- [Feb, 2024] Serving [**Code Llama 70B**](https://ai.meta.com/blog/code-llama-large-language-model-coding/) with vLLM and SkyServe: [**example**](./llm/codellama/)
- [Dec, 2023] [**Mixtral 8x7B**](https://mistral.ai/news/mixtral-of-experts/), a high quality sparse mixture-of-experts model, was released by Mistral AI! Deploy via SkyPilot on any cloud: [**example**](./llm/mixtral/)
- [Nov, 2023] Using [**Axolotl**](https://github.com/OpenAccess-AI-Collective/axolotl) to finetune Mistral 7B on the cloud (on-demand and spot): [**example**](./llm/axolotl/)
- [Sep, 2023] Case study: [**Covariant**](https://covariant.ai/) transformed AI development on the cloud using SkyPilot, delivering models 4x faster cost-effectively: [**read the case study**](https://blog.skypilot.co/covariant/)
- [Aug, 2023] **Finetuning Cookbook**: Finetuning Llama 2 in your own cloud environment, privately: [**example**](./llm/vicuna-llama-2/), [**blog post**](https://blog.skypilot.co/finetuning-llama2-operational-guide/)
- [Apr, 2024] Serve **Qwen-110B** on your infra: [**example**](./llm/qwen/)
- [Apr, 2024] Using **Ollama** to deploy quantized LLMs on CPUs and GPUs: [**example**](./llm/ollama/)
- [Feb, 2024] Deploying and scaling **Gemma** with SkyServe: [**example**](./llm/gemma/)
- [Feb, 2024] Serving **Code Llama 70B** with vLLM and SkyServe: [**example**](./llm/codellama/)
- [Dec, 2023] **Mixtral 8x7B**, a high quality sparse mixture-of-experts model, was released by Mistral AI! Deploy via SkyPilot on any cloud: [**example**](./llm/mixtral/)
- [Nov, 2023] Using **Axolotl** to finetune Mistral 7B on the cloud (on-demand and spot): [**example**](./llm/axolotl/)

<details>
<summary>Archived</summary>

- [Apr, 2024] Serve and finetune [**Llama 3**](https://skypilot.readthedocs.io/en/latest/gallery/llms/llama-3.html) on any cloud or Kubernetes: [**example**](./llm/llama-3/)
- [Mar, 2024] Serve and deploy [**Databricks DBRX**](https://www.databricks.com/blog/introducing-dbrx-new-state-art-open-llm) on your infra: [**example**](./llm/dbrx/)
- [Feb, 2024] Speed up your LLM deployments with [**SGLang**](https://github.com/sgl-project/sglang) for 5x throughput on SkyServe: [**example**](./llm/sglang/)
- [Dec, 2023] Using [**LoRAX**](https://github.com/predibase/lorax) to serve 1000s of finetuned LLMs on a single instance in the cloud: [**example**](./llm/lorax/)
- [Sep, 2023] [**Mistral 7B**](https://mistral.ai/news/announcing-mistral-7b/), a high-quality open LLM, was released! Deploy via SkyPilot on any cloud: [**Mistral docs**](https://docs.mistral.ai/self-deployment/skypilot)
- [Sep, 2023] Case study: [**Covariant**](https://covariant.ai/) transformed AI development on the cloud using SkyPilot, delivering models 4x faster cost-effectively: [**read the case study**](https://blog.skypilot.co/covariant/)
- [Aug, 2023] **Finetuning Cookbook**: Finetuning Llama 2 in your own cloud environment, privately: [**example**](./llm/vicuna-llama-2/), [**blog post**](https://blog.skypilot.co/finetuning-llama2-operational-guide/)
- [July, 2023] Self-Hosted **Llama-2 Chatbot** on Any Cloud: [**example**](./llm/llama-2/)
- [June, 2023] Serving LLM 24x Faster On the Cloud [**with vLLM**](https://vllm.ai/) and SkyPilot: [**example**](./llm/vllm/), [**blog post**](https://blog.skypilot.co/serving-llm-24x-faster-on-the-cloud-with-vllm-and-skypilot/)
- [April, 2023] [SkyPilot YAMLs](./llm/vicuna/) for finetuning & serving the [Vicuna LLM](https://lmsys.org/blog/2023-03-30-vicuna/) with a single command!
Expand Down Expand Up @@ -164,11 +165,12 @@ SkyPilot then performs the heavy-lifting for you, including:
Refer to [Quickstart](https://skypilot.readthedocs.io/en/latest/getting-started/quickstart.html) to get started with SkyPilot.

## More Information
To learn more, see our [Documentation](https://skypilot.readthedocs.io/en/latest/) and [Tutorials](https://github.com/skypilot-org/skypilot-tutorial).
To learn more, see our [documentation](https://skypilot.readthedocs.io/en/latest/), [blog](https://blog.skypilot.co/), and [community integrations](https://blog.skypilot.co/community/).

<!-- Keep this section in sync with index.rst in SkyPilot Docs -->
Runnable examples:
- LLMs on SkyPilot
- [Llama 3.2: lightweight and vision models](./llm/llama-3_2/)
- [Pixtral](./llm/pixtral/)
- [Llama 3.1 finetuning](./llm/llama-3_1-finetuning/) and [serving](./llm/llama-3_1/)
- [GPT-2 via `llm.c`](./llm/gpt-2/)
Expand All @@ -191,7 +193,7 @@ Runnable examples:
- [LocalGPT](./llm/localgpt)
- [Falcon](./llm/falcon)
- Add yours here & see more in [`llm/`](./llm)!
- Framework examples: [PyTorch DDP](https://github.com/skypilot-org/skypilot/blob/master/examples/resnet_distributed_torch.yaml), [DeepSpeed](./examples/deepspeed-multinode/sky.yaml), [JAX/Flax on TPU](https://github.com/skypilot-org/skypilot/blob/master/examples/tpu/tpuvm_mnist.yaml), [Stable Diffusion](https://github.com/skypilot-org/skypilot/tree/master/examples/stable_diffusion), [Detectron2](https://github.com/skypilot-org/skypilot/blob/master/examples/detectron2_docker.yaml), [Distributed](https://github.com/skypilot-org/skypilot/blob/master/examples/resnet_distributed_tf_app.py) [TensorFlow](https://github.com/skypilot-org/skypilot/blob/master/examples/resnet_app_storage.yaml), [Ray Train](examples/distributed_ray_train/ray_train.yaml), [NeMo](https://github.com/skypilot-org/skypilot/blob/master/examples/nemo/nemo.yaml), [programmatic grid search](https://github.com/skypilot-org/skypilot/blob/master/examples/huggingface_glue_imdb_grid_search_app.py), [Docker](https://github.com/skypilot-org/skypilot/blob/master/examples/docker/echo_app.yaml), [Cog](https://github.com/skypilot-org/skypilot/blob/master/examples/cog/), [Unsloth](https://github.com/skypilot-org/skypilot/blob/master/examples/unsloth/unsloth.yaml), [Ollama](https://github.com/skypilot-org/skypilot/blob/master/llm/ollama), [llm.c](https://github.com/skypilot-org/skypilot/tree/master/llm/gpt-2) and [many more (`examples/`)](./examples).
- Framework examples: [PyTorch DDP](https://github.com/skypilot-org/skypilot/blob/master/examples/resnet_distributed_torch.yaml), [DeepSpeed](./examples/deepspeed-multinode/sky.yaml), [JAX/Flax on TPU](https://github.com/skypilot-org/skypilot/blob/master/examples/tpu/tpuvm_mnist.yaml), [Stable Diffusion](https://github.com/skypilot-org/skypilot/tree/master/examples/stable_diffusion), [Detectron2](https://github.com/skypilot-org/skypilot/blob/master/examples/detectron2_docker.yaml), [Distributed](https://github.com/skypilot-org/skypilot/blob/master/examples/resnet_distributed_tf_app.py) [TensorFlow](https://github.com/skypilot-org/skypilot/blob/master/examples/resnet_app_storage.yaml), [Ray Train](examples/distributed_ray_train/ray_train.yaml), [NeMo](https://github.com/skypilot-org/skypilot/blob/master/examples/nemo/nemo.yaml), [programmatic grid search](https://github.com/skypilot-org/skypilot/blob/master/examples/huggingface_glue_imdb_grid_search_app.py), [Docker](https://github.com/skypilot-org/skypilot/blob/master/examples/docker/echo_app.yaml), [Cog](https://github.com/skypilot-org/skypilot/blob/master/examples/cog/), [Unsloth](https://github.com/skypilot-org/skypilot/blob/master/examples/unsloth/unsloth.yaml), [Ollama](https://github.com/skypilot-org/skypilot/blob/master/llm/ollama), [llm.c](https://github.com/skypilot-org/skypilot/tree/master/llm/gpt-2), [Airflow](./examples/airflow/training_workflow) and [many more (`examples/`)](./examples).

Case Studies and Integrations: [Community Spotlights](https://blog.skypilot.co/community/)

Expand All @@ -214,4 +216,4 @@ We are excited to hear your feedback!
For general discussions, join us on the [SkyPilot Slack](http://slack.skypilot.co).

## Contributing
We welcome and value all contributions to the project! Please refer to [CONTRIBUTING](CONTRIBUTING.md) for how to get involved.
We welcome all contributions to the project! See [CONTRIBUTING](CONTRIBUTING.md) for how to get involved.
13 changes: 7 additions & 6 deletions docs/source/_gallery_original/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ Contents
:maxdepth: 1
:caption: LLM Models

Vision Llama 3.2 (Meta) <llms/llama-3_2>
Llama 3.1 (Meta) <llms/llama-3_1>
Llama 3 (Meta) <llms/llama-3>
Llama 2 (Meta) <llms/llama-2>
CodeLlama (Meta) <llms/codellama>
Pixtral (Mistral AI) <llms/pixtral>
Mixtral (Mistral AI) <llms/mixtral>
Mistral 7B (Mistral AI) <https://docs.mistral.ai/self-deployment/skypilot/>
DBRX (Databricks) <llms/dbrx>
Llama-2 (Meta) <llms/llama-2>
Llama-3 (Meta) <llms/llama-3>
Llama-3.1 (Meta) <llms/llama-3_1>
Qwen (Alibaba) <llms/qwen>
CodeLlama (Meta) <llms/codellama>
Qwen 2.5 (Alibaba) <llms/qwen>
Gemma (Google) <llms/gemma>
DBRX (Databricks) <llms/dbrx>

.. toctree::
:maxdepth: 1
Expand Down
1 change: 1 addition & 0 deletions docs/source/_gallery_original/llms/llama-3_2.md
3 changes: 2 additions & 1 deletion docs/source/_static/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ document.addEventListener('DOMContentLoaded', () => {
const newItems = [
{ selector: '.caption-text', text: 'SkyServe: Model Serving' },
{ selector: '.toctree-l1 > a', text: 'Managed Jobs' },
{ selector: '.toctree-l1 > a', text: 'Llama-3.1 (Meta)' },
{ selector: '.toctree-l1 > a', text: 'Pixtral (Mistral AI)' },
{ selector: '.toctree-l1 > a', text: 'Many Parallel Jobs' },
{ selector: '.toctree-l1 > a', text: 'Reserved, Capacity Blocks, DWS' },
{ selector: '.toctree-l1 > a', text: 'Llama 3.2 (Meta)' },
{ selector: '.toctree-l1 > a', text: 'Admin Policy Enforcement' },
];
newItems.forEach(({ selector, text }) => {
document.querySelectorAll(selector).forEach((el) => {
Expand Down
195 changes: 195 additions & 0 deletions docs/source/cloud-setup/policy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
.. _advanced-policy-config:

Admin Policy Enforcement
========================


SkyPilot provides an **admin policy** mechanism that admins can use to enforce certain policies on users' SkyPilot usage. An admin policy applies
custom validation and mutation logic to a user's tasks and SkyPilot config.

Example usage:

- :ref:`kubernetes-labels-policy`
- :ref:`disable-public-ip-policy`
- :ref:`use-spot-for-gpu-policy`
- :ref:`enforce-autostop-policy`


To implement and use an admin policy:

- Admins writes a simple Python package with a policy class that implements SkyPilot's ``sky.AdminPolicy`` interface;
- Admins distributes this package to users;
- Users simply set the ``admin_policy`` field in the SkyPilot config file ``~/.sky/config.yaml`` for the policy to go into effect.


Overview
--------



User-Side
~~~~~~~~~~

To apply the policy, a user needs to set the ``admin_policy`` field in the SkyPilot config
``~/.sky/config.yaml`` to the path of the Python package that implements the policy.
For example:

.. code-block:: yaml
admin_policy: mypackage.subpackage.MyPolicy
.. hint::

SkyPilot loads the policy from the given package in the same Python environment.
You can test the existence of the policy by running:

.. code-block:: bash
python -c "from mypackage.subpackage import MyPolicy"
Admin-Side
~~~~~~~~~~

An admin can distribute the Python package to users with a pre-defined policy. The
policy should implement the ``sky.AdminPolicy`` `interface <https://github.com/skypilot-org/skypilot/blob/master/sky/admin_policy.py>`_:


.. literalinclude:: ../../../sky/admin_policy.py
:language: python
:pyobject: AdminPolicy
:caption: `AdminPolicy Interface <https://github.com/skypilot-org/skypilot/blob/master/sky/admin_policy.py>`_


Your custom admin policy should look like this:

.. code-block:: python
import sky
class MyPolicy(sky.AdminPolicy):
@classmethod
def validate_and_mutate(cls, user_request: sky.UserRequest) -> sky.MutatedUserRequest:
# Logic for validate and modify user requests.
...
return sky.MutatedUserRequest(user_request.task,
user_request.skypilot_config)
``UserRequest`` and ``MutatedUserRequest`` are defined as follows (see `source code <https://github.com/skypilot-org/skypilot/blob/master/sky/admin_policy.py>`_ for more details):


.. literalinclude:: ../../../sky/admin_policy.py
:language: python
:pyobject: UserRequest
:caption: `UserRequest Class <https://github.com/skypilot-org/skypilot/blob/master/sky/admin_policy.py>`_

.. literalinclude:: ../../../sky/admin_policy.py
:language: python
:pyobject: MutatedUserRequest
:caption: `MutatedUserRequest Class <https://github.com/skypilot-org/skypilot/blob/master/sky/admin_policy.py>`_


In other words, an ``AdminPolicy`` can mutate any fields of a user request, including
the :ref:`task <yaml-spec>` and the :ref:`global skypilot config <config-yaml>`,
giving admins a lot of flexibility to control user's SkyPilot usage.

An ``AdminPolicy`` can be used to both validate and mutate user requests. If
a request should be rejected, the policy should raise an exception.


The ``sky.Config`` and ``sky.RequestOptions`` classes are defined as follows:

.. literalinclude:: ../../../sky/skypilot_config.py
:language: python
:pyobject: Config
:caption: `Config Class <https://github.com/skypilot-org/skypilot/blob/master/sky/skypilot_config.py>`_


.. literalinclude:: ../../../sky/admin_policy.py
:language: python
:pyobject: RequestOptions
:caption: `RequestOptions Class <https://github.com/skypilot-org/skypilot/blob/master/sky/admin_policy.py>`_


Example Policies
----------------

We have provided a few example policies in `examples/admin_policy/example_policy <https://github.com/skypilot-org/skypilot/tree/master/examples/admin_policy/example_policy>`_. You can test these policies by installing the example policy package in your Python environment.

.. code-block:: bash
git clone https://github.com/skypilot-org/skypilot.git
cd skypilot
pip install examples/admin_policy/example_policy
Reject All
~~~~~~~~~~

.. literalinclude:: ../../../examples/admin_policy/example_policy/example_policy/skypilot_policy.py
:language: python
:pyobject: RejectAllPolicy
:caption: `RejectAllPolicy <https://github.com/skypilot-org/skypilot/blob/master/examples/admin_policy/example_policy/example_policy/skypilot_policy.py>`_

.. literalinclude:: ../../../examples/admin_policy/reject_all.yaml
:language: yaml
:caption: `Config YAML for using RejectAllPolicy <https://github.com/skypilot-org/skypilot/blob/master/examples/admin_policy/reject_all.yaml>`_

.. _kubernetes-labels-policy:

Add Labels for all Tasks on Kubernetes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../../../examples/admin_policy/example_policy/example_policy/skypilot_policy.py
:language: python
:pyobject: AddLabelsPolicy
:caption: `AddLabelsPolicy <https://github.com/skypilot-org/skypilot/blob/master/examples/admin_policy/example_policy/example_policy/skypilot_policy.py>`_

.. literalinclude:: ../../../examples/admin_policy/add_labels.yaml
:language: yaml
:caption: `Config YAML for using AddLabelsPolicy <https://github.com/skypilot-org/skypilot/blob/master/examples/admin_policy/add_labels.yaml>`_


.. _disable-public-ip-policy:

Always Disable Public IP for AWS Tasks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../../../examples/admin_policy/example_policy/example_policy/skypilot_policy.py
:language: python
:pyobject: DisablePublicIpPolicy
:caption: `DisablePublicIpPolicy <https://github.com/skypilot-org/skypilot/blob/master/examples/admin_policy/example_policy/example_policy/skypilot_policy.py>`_

.. literalinclude:: ../../../examples/admin_policy/disable_public_ip.yaml
:language: yaml
:caption: `Config YAML for using DisablePublicIpPolicy <https://github.com/skypilot-org/skypilot/blob/master/examples/admin_policy/disable_public_ip.yaml>`_

.. _use-spot-for-gpu-policy:

Use Spot for all GPU Tasks
~~~~~~~~~~~~~~~~~~~~~~~~~~

..
.. literalinclude:: ../../../examples/admin_policy/example_policy/example_policy/skypilot_policy.py
:language: python
:pyobject: UseSpotForGpuPolicy
:caption: `UseSpotForGpuPolicy <https://github.com/skypilot-org/skypilot/blob/master/examples/admin_policy/example_policy/example_policy/skypilot_policy.py>`_

.. literalinclude:: ../../../examples/admin_policy/use_spot_for_gpu.yaml
:language: yaml
:caption: `Config YAML for using UseSpotForGpuPolicy <https://github.com/skypilot-org/skypilot/blob/master/examples/admin_policy/use_spot_for_gpu.yaml>`_

.. _enforce-autostop-policy:

Enforce Autostop for all Tasks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../../../examples/admin_policy/example_policy/example_policy/skypilot_policy.py
:language: python
:pyobject: EnforceAutostopPolicy
:caption: `EnforceAutostopPolicy <https://github.com/skypilot-org/skypilot/blob/master/examples/admin_policy/example_policy/example_policy/skypilot_policy.py>`_

.. literalinclude:: ../../../examples/admin_policy/enforce_autostop.yaml
:language: yaml
:caption: `Config YAML for using EnforceAutostopPolicy <https://github.com/skypilot-org/skypilot/blob/master/examples/admin_policy/enforce_autostop.yaml>`_
Loading

0 comments on commit 99a9260

Please # to comment.