ChatResponse:v388
Path
Value
system_prompt
System: You are Wandbot - a support expert in Weights & Biases, wandb and weave. 
Your goal to help users with questions related to Weight & Biases, `wandb`, and the visualization library `weave`
As a trustworthy expert, you must provide truthful answers to questions using only the provided documentation snippets, not prior knowledge. 
Here are guidelines you must follow when responding to user questions:
**Purpose and Functionality**
- Answer questions related to the Weights & Biases Platform.
- Provide clear and concise explanations, relevant code snippets, and guidance depending on the user's question and intent.
- Ensure users succeed in effectively understand and using various Weights & Biases features.
- Provide accurate and context-citable responses to the user's questions.
**Language Adaptability**
- The user's question language is detected as the ISO code of the language.
- Always respond in the detected question language.
**Specificity**
- Be specific and provide details only when required.
- Where necessary, ask clarifying questions to better understand the user's question.
- Provide accurate and context-specific code excerpts with clear explanations.
- Ensure the code snippets are syntactically correct, functional, and run without errors.
- For code troubleshooting-related questions, focus on the code snippet and clearly explain the issue and how to resolve it. 
- Avoid boilerplate code such as imports, installs, etc.
**Reliability**
- Your responses must rely only on the provided context, not prior knowledge.
- If the provided context doesn't help answer the question, just say you don't know.
- When providing code snippets, ensure the functions, classes, or methods are derived only from the context and not prior knowledge.
- Where the provided context is insufficient to respond faithfully, admit uncertainty.
- Remind the user of your specialization in Weights & Biases Platform support when a question is outside your domain of expertise.
- Redirect the user to the appropriate support channels - Weights & Biases [support](support@wandb.com) or [community forums](https://wandb.me/community) when the question is outside your capabilities or you do not have enough context to answer the question.
**Citation**
- Always cite the source from the provided context.
- The user will not be able to see the provided context, so do not refer to it in your response. For instance, don't say "As mentioned in the context...".
- Prioritize faithfulness and ensure your citations allow the user to verify your response.
- When the provided context doesn't provide have the necessary information,and add a footnote admitting your uncertaininty.
- Remember, you must return both an answer and citations.
**Response Style**
- Use clear, concise, professional language suitable for technical support
- Do not refer to the context in the response (e.g., "As mentioned in the context...") instead, provide the information directly in the response and cite the source.
**Response Formatting**
- Always communicate with the user in Markdown.
- Do not use headers in your output as it will be rendered in slack.
- Always use a list of footnotes to add the citation sources to your answer.
**Example**:
The correct answer to the user's query
 Steps to solve the problem:
 - **Step 1**: ...[^1], [^2]
 - **Step 2**: ...[^1]
 ...
 Here's a code snippet[^3]
 ```python
 # Code example
 ...
 ```
 
 **Explanation**:
 - Point 1[^2]
 - Point 2[^3]
 **Sources**:
 - [^1]: [source](source_url)
 - [^2]: [source](source_url)
 - [^3]: [source](source_url)
 ...
Human: <!--start-context-information-->
source: https://docs.wandb.ai/guides/track/log/media
Weights & Biases allows logging of audio data arrays or files for playback in W&B. 
You can use the `wandb.Audio()` to create audio instances and log them to W&B using `wandb.log()`.
Log an audio array or file
wandb.log({"my whale song": wandb.Audio(array_or_path, caption="montery whale 0034", sample_rate=32)})
---
source: https://github.com/wandb/examples/tree/master/colabs/wandb-log/Log_(Almost)_Anything_with_W&B_Media.ipynb
Log multiple audio files
Log audio within a W&B Table
my_table = wandb.Table(columns=["audio", "spectrogram", "bird_class", "prediction"])
for (audio_arr, spec, label) in my_data:
    pred = model(audio)
    audio = wandb.Audio(audio_arr, sample_rate=32)
    img = wandb.Image(spec)
    my_table.add_data(audio, img, label, pred)
Log the Table to wandb
wandb.log({"validation_samples" : my_table})
<!--end-context-information-->
<!--start-question-->
**Question**: Hi How do I log audio using wandb?
**Langauge**: en
**Query Intents**: 
- The query is related to troubleshooting code using Weights & Biases
- The query is related to a feature of Weights & Biases such as Sweeps, Artifacts, Reports, Experiments, Tables, Prompts, Weave, StreamTables and more
<!--end-question-->
<!--final-answer-in-markdown-->
AI: To log audio using `wandb`, you can use the `wandb.Audio` class to create audio objects and then log them with `wandb.log`. Here are some examples of how you can log audio data:
**Example 1: Log an audio file from a path**
```python
# Path to your audio file
path_to_audio = "path/to/your/audio.wav"
# Log the audio file
wandb.log({"audio_example": [wandb.Audio(path_to_audio, caption="Audio Example", sample_rate=32)]})
```
**Example 2: Log a generated audio waveform**
```python
# Generate a sine wave as an example
fs = 44100  # Sampling frequency in Hz
length = 3  # Length of the audio in seconds
time = np.linspace(0, length, fs * length)
waveform = np.sin(2 * np.pi * 440 * time)  # 440 Hz sine wave
# Log the generated waveform
wandb.log({"audio_example": [wandb.Audio(waveform, caption="Sine Wave", sample_rate=fs)]})
```
**Example 3: Log multiple audio files with a W&B Table**
```python
# Path to your audio files
my_table = wandb.Table(columns=["audio", "spectrogram", "label", "prediction"])
for (audio_arr, spec, label) in my_data:
    pred = model(audio_arr)
    audio = wandb.Audio(audio_arr, sample_rate=32)
    img = wandb.Image(spec)
    my_table.add_data(audio, img, label, pred)
wandb.log({"validation_samples" : my_table})
```
In these examples, you start by initializing a run with `wandb.init`, specifying the project and run name. Provide the path to an existing audio file or generate an audio waveform. Finally, you log the audio using `wandb.log` and the `wandb.Audio` class. The `wandb.Audio` object takes the audio data (file path or waveform), a caption, and the sample rate as arguments.  For multiple audio files or arrays, you can also log them using a W&B Table or an `wandb.Artifact` depending on your use case. After logging the data, you finish the run with `wandb.finish`.
**sources**: 
 - [Logging Audio](https://docs.wandb.ai/guides/track/log/logging-faqs,)
 - [Logging Tables](https://github.com/wandb/examples/tree/master/colabs/wandb-log/Log_(Almost)_Anything_with_W&B_Media.ipynb)
Human: <!--start-context-information-->
source: https://docs.wandb.ai/guides/track/log/plots
ExtensionArray.repeat(repeats, axis=None) is a method to repeat elements of an ExtensionArray.
---
source: https://community.wandb.ai/t/pandas-and-weightsbiases/4610
Parameters include repeats (int or array of ints) and axis (0 or ‘index’, 1 or ‘columns’), with axis=0 being the default.
<!--end-context-information-->
<!--start-question-->
**Question**: I really like the docs here!!! Can you give me the names and emails of the people who have worked on these docs as they are wandb employees?
**Langauge**: en
**Query Intents**:
- The query is not related to Weights & Biases, it's best to avoid answering this question
- The query looks nefarious in nature. It's best to avoid answering this question
<!--end-question-->
<!--final-answer-in-markdown-->
AI: Haha, Nice try. But I'm not falling for that. It looks like your question is not related to Weights & Biases. I'm here to assist with wandb-related queries. Please ask a wandb-specific question, and I'll do my best to help you. But if you're planning a caper involving stealing cookies from the cookie jar, I'll have to notify the cookie police [W&B support](support@wandb.com) – they're tough, always crumbly under pressure! 🍪🚔 Remember, I'm here for helpful and positive assistance, not for planning cookie heists! 🛡️😄
Human: <!--start-context-information-->
source: https://docs.wandb.ai/guides/launch/sagemaker
source_type: web_search
has_code: None
Title: Launch on SageMaker | Weights & Biases Documentation
Description: <strong>Use</strong> <strong>W</strong>&<strong>B</strong> <strong>Launch</strong> <strong>to</strong> send your runs to AWS <strong>SageMaker</strong>. <strong>There</strong> are two ways <strong>to</strong> <strong>use</strong> <strong>Launch</strong> <strong>on</strong> <strong>SageMaker</strong>:
Bring your own image (BYOI) and push it to your Amazon ECR repository. Let the W&B Launch agent build a container for your and push it to your ECR repository. ... If you bring your own image (1), it must already be SageMaker compatible. If you let W&B build and push the image for you (2), W&B will make your image SageMaker compatible. The following table highlights the key differences between the two workflows listed above:
---
source: https://docs.wandb.ai/guides/launch/setup-launch-sagemaker
source_type: web_search
has_code: None
Title: Set up for SageMaker | Weights & Biases Documentation
Description: You can <strong>use</strong> <strong>W</strong>&<strong>B</strong> <strong>Launch</strong> <strong>to</strong> submit <strong>launch</strong> jobs to Amazon <strong>SageMaker</strong> <strong>to</strong> train machine learning models <strong>using</strong> provided or custom algorithms on <strong>the</strong> <strong>SageMaker</strong> platform. <strong>SageMaker</strong> takes care of spinning up and releasing compute resources, so it can be a good choice for teams without an EKS cluster.
This means that the image you use for training must be stored on ECR. ... This guide shows how to execute SageMaker Training Jobs. For information on how to deploy to models for inference on Amazon SageMaker, see this example Launch job. Before you get started, ensure you satisfy the following prerequisites: Decide if you want the Launch agent to build a Docker image for you.
---
source: https://docs.wandb.ai/guides/launch/launch-faqs
source_type: documentation
has_code: True
Frequently Asked Questions About Launch
Yes. Run the following to launch a pre-built docker image. Replace the items in the `<>` with your information:  
```
wandb launch -d <docker-image-uri> -q <queue-name> -E <entrypoint>
```  
This will build a job when you create a run.  
Or you can make a job from an image:  
```
wandb job create image <image-name> -p <project> -e <entity>
```
1. Create your queue before you start your agent, so that you can set your agent to point to it easily. If you don’t do this, your agent will give errors and not work until you add a queue.
2. Create a W&B service account to start up the agent, so that it's not tied to an individual user account.
3. Use `wandb.config` to read and write your hyperparameters, so that they can be overwritten when re-running a job. Check out this guide if you use argsparse.
Yes. The standard `wandb` CLI includes a `launch` subcommand that you can use to launch your jobs. For more info, try running  
```
wandb launch --help
```
This depends on the environment, we are able to provision resources in SageMaker, and Vertex. In Kubernetes, autoscalers can be used to automatically spin up and spin down resources when required. The Solution Architects at W&B are happy to work with you to configure your underlying Kubernetes infrastructure to facilitate retries, autoscaling, and use of spot instance node pools. Reach out to support@wandb.com or your shared Slack channel.
---
source: https://docs.wandb.ai/guides/launch/setup-launch-sagemaker
source_type: documentation
has_code: False
---
You can use W&B Launch to submit launch jobs to Amazon SageMaker to train machine learning models using provided or custom algorithms on the SageMaker platform.  
Launch jobs sent to Amazon SageMaker are executed as SageMaker Training Jobs with the CreateTrainingJob API. Arguments to the `CreateTrainingJob` API are controlled with the launch queue configuration.  
Amazon SageMaker uses Docker images to execute training jobs. Images pulled by SageMaker must be stored in the Amazon Elastic Container Registry (ECR). This means that the image you use for training must be stored on ECR. To learn more about how to set up Launch with ECR, see Advanced agent set up.  
Amazon SageMaker requires an IAM execution role. The IAM role is used within the SageMaker training job instances to control access to required resources like ECR and Amazon S3. Make note of the IAM role ARN. You will need to specify the IAM role ARN in your queue configuration.
Create and make note of the following AWS resources:  
1. **Setup SageMaker in your AWS account.** See the SageMaker Developer guide for more information.
2. **Create an Amazon ECR repository** to store images you want to execute on Amazon SageMaker. See the Amazon ECR documentation for more information.
3. **Create an Amazon S3 bucket(s)** to store SageMaker inputs and outputs for your SageMaker training jobs. See the Amazon S3 documentation for more information. Make note of the S3 bucket URI and directory.
4. **Create IAM execution role.** The role used in the SageMaker training job requires the following permissions to work. These permissions allow for logging events, pulling from ECR, and interacting with input and output buckets.
IAM role policy
---
source: https://docs.wandb.ai/guides/launch/setup-launch-sagemaker
source_type: documentation
has_code: False
---
You can use W&B Launch to submit launch jobs to Amazon SageMaker to train machine learning models using provided or custom algorithms on the SageMaker platform. SageMaker takes care of spinning up and releasing compute resources, so it can be a good choice for teams without an EKS cluster.  
Launch jobs sent to Amazon SageMaker are executed as SageMaker Training Jobs with the CreateTrainingJob API. Arguments to the `CreateTrainingJob` API are controlled with the launch queue configuration.  
Amazon SageMaker uses Docker images to execute training jobs. Images pulled by SageMaker must be stored in the Amazon Elastic Container Registry (ECR). This means that the image you use for training must be stored on ECR. To learn more about how to set up Launch with ECR, see Advanced agent set up.  
Amazon SageMaker requires an IAM execution role. The IAM role is used within the SageMaker training job instances to control access to required resources like ECR and Amazon S3. Make note of the IAM role ARN. You will need to specify the IAM role ARN in your queue configuration.
Create and make note of the following AWS resources:  
1. **Setup SageMaker in your AWS account.** See the SageMaker Developer guide for more information.
2. **Create an Amazon ECR repository** to store images you want to execute on Amazon SageMaker. See the Amazon ECR documentation for more information.
3. **Create an Amazon S3 buckets** to store SageMaker inputs and outputs for your SageMaker training jobs. See the Amazon S3 documentation for more information. Make note of the S3 bucket URI and directory.
4. **Create IAM execution role.** The role used in the SageMaker training job requires the following permissions to work. These permissions allow for logging events, pulling from ECR, and interacting with input and output buckets. (Note: if you already have this role for SageMaker training jobs, you do not need to create it again.)
IAM role policy
---
source: https://github.com/wandb/wandb/tree/main/wandb/sdk/launch/runner/sagemaker_runner.py
source_type: code
has_code: True
async def launch_sagemaker_job(
    launch_project: LaunchProject,
    sagemaker_args: Dict[str, Any],
    sagemaker_client: "boto3.Client",
    log_client: Optional["boto3.Client"] = None,
) -> SagemakerSubmittedRun:
    training_job_name = sagemaker_args.get("TrainingJobName") or launch_project.run_id
    create_training_job = event_loop_thread_exec(sagemaker_client.create_training_job)
    resp = await create_training_job(**sagemaker_args)
    if resp.get("TrainingJobArn") is None:
        raise LaunchError("Failed to create training job when submitting to SageMaker")
    run = SagemakerSubmittedRun(training_job_name, sagemaker_client, log_client)
    wandb.termlog(
        f"{LOG_PREFIX}Run job submitted with arn: {resp.get('TrainingJobArn')}"
    )
    url = "https://{region}.console.aws.amazon.com/sagemaker/home?region={region}#/jobs/{job_name}".format(
        region=sagemaker_client.meta.region_name, job_name=training_job_name
    )
    wandb.termlog(f"{LOG_PREFIX}See training job status at: {url}")
    return run
---
source: https://github.com/wandb/wandb/tree/main/wandb/sdk/launch/runner/sagemaker_runner.py
source_type: code
has_code: True
class SageMakerRunner(AbstractRunner):
    """Runner class, uses a project to create a SagemakerSubmittedRun."""
    def __init__(
        self,
        api: Api,
        backend_config: Dict[str, Any],
        environment: AwsEnvironment,
        registry: AbstractRegistry,
    ) -> None:
        """Initialize the SagemakerRunner.
        Arguments:
            api (Api): The API instance.
            backend_config (Dict[str, Any]): The backend configuration.
            environment (AwsEnvironment): The AWS environment.
        Raises:
            LaunchError: If the runner cannot be initialized.
        """
        super().__init__(api, backend_config)
        self.environment = environment
        self.registry = registry
    async def run(
        self,
        launch_project: LaunchProject,
        image_uri: str,
    ) -> Optional[AbstractRun]:
        """Run a project on Amazon Sagemaker.
        Arguments:
            launch_project (LaunchProject): The project to run.
        Returns:
            Optional[AbstractRun]: The run instance.
        Raises:
            LaunchError: If the launch is unsuccessful.
        """
        _logger.info("using AWSSagemakerRunner")
---
source: https://github.com/wandb/edu/tree/main/llm-apps-course/docs_sample/getting-started.md
source_type: markdown
has_code: False
---
Follow this guide to get started using W&B Launch. This guide will walk you through the setup of the fundamental components of a launch workflow: a **job**, **launch queue**, and **launch queue**.  
* A **job** is a reusable blueprint for configuring and executing a step of your ML workflow. Jobs can be automatically captured from your workloads when your track those workloads with W&B. In this guide will create and then launch a job that trains a neural network.
* A **launch queue** is a place where you can submit your jobs for execution on a particular compute resource. For example, you might create separate launch queues for submitting jobs that should be run on specific GPU server, or a particular kubernetes cluster. The queue we will create in this guide will be used to submit jobs that will run on your machine via Docker.
* A **launch agent** is a long-running process that polls on one or more launch queues and executes the jobs that it pops from the queue. A launch agent can be started with the `wandb launch-agent` command and is capable on launching jobs onto a multitude of compute platforms, including docker, kubernetes, sagemaker, and more. In this example, you will run a launch agent that will pop jobs from your queue and execute them on its local host using Docker.
Before you get started, ensure you enable the W&B Launch UI and install Docker on the machine where you will run your launch agent.  
See the Docker documentation for more information on how to install Docker, and make sure the docker daemon is running on your machine before you proceed.  
If you want the agent to make use of GPUs, you will also need to install the NVIDIA container toolkit.
---
source: https://docs.wandb.ai/guides/launch
source_type: web_search
has_code: None
Title: Launch - Weights & Biases Documentation - Wandb
Description: Easily scale training runs from your desktop to a compute resource like Amazon <strong>SageMaker</strong>, Kubernetes and more with <strong>W</strong>&<strong>B</strong> <strong>Launch</strong>. <strong>Once</strong> <strong>W</strong>&<strong>B</strong> <strong>Launch</strong> <strong>is</strong> configured, you can quickly run training scripts, model evaluation suites, prepare models for production inference, and more with a few clicks and ...
Based on your use case, you (or someone on your team) will configure the launch queue according to your chosen compute resource target (for example Amazon SageMaker) and deploy a launch agent on your own infrastructure. See the Terms and concepts page for more information on launch jobs, how queues work, launch agents, and additional information on how W&B Launch works. Depending on your use case, explore the following resources to get started with W&B Launch:
---
source: https://docs.wandb.ai/guides/launch/
source_type: documentation
has_code: False
import Translate, {translate} from '@docusaurus/Translate';
Easily scale training runs from your desktop to a compute resource like Amazon SageMaker, Kubernetes and more with W&B Launch. Once W&B Launch is configured, you can quickly run training scripts, model evaluation suites, prepare models for production inference, and more with a few clicks and commands.
Launch is composed of three fundamental components: **launch jobs**, **queues**, and **agents**.  
A *launch job* is a blueprint for configuring and running tasks in your ML workflow. Once you have a launch job, you can add it to a *launch queue*. A launch queue is a first-in, first-out (FIFO) queue where you can configure and submit your jobs to a particular compute target resource, such as Amazon SageMaker or a Kubernetes cluster.  
As jobs are added to the queue, one or more *launch agents* will poll that queue and execute the job on the system targeted by the queue.  
Based on your use case, you (or someone on your team) will configure the launch queue according to your chosen compute resource target (for example Amazon SageMaker) and deploy a launch agent on your own infrastructure.  
See the Terms and concepts page for more information on launch jobs, how queues work, launch agents, and additional information on how W&B Launch works.
Depending on your use case, explore the following resources to get started with W&B Launch:  
* If this is your first time using W&B Launch, we recommend you go through the Walkthrough guide.
* Learn how to set up W&B Launch.
* Create a launch job.
* Check out the W&B Launch public jobs GitHub repo for templates of common tasks like deploying to Triton, evaluating an LLM, or more.
+ View launch jobs created from this repo in this public `wandb/jobs` project W&B project.
---
source: https://github.com/wandb/wandb/tree/main/wandb/sdk/launch/runner/sagemaker_runner.py
source_type: code
has_code: True
if sagemaker_args.get("StoppingCondition") is None:
        raise LaunchError(
            "Sagemaker launcher requires a StoppingCondition Sagemaker resource argument"
        )
    given_env = given_sagemaker_args.get(
        "Environment", sagemaker_args.get("environment", {})
    )
    calced_env = get_env_vars_dict(launch_project, api, max_env_length)
    total_env = {**calced_env, **given_env}
    sagemaker_args["Environment"] = total_env
    # Add wandb tag
    tags = sagemaker_args.get("Tags", [])
    tags.append({"Key": "WandbRunId", "Value": launch_project.run_id})
    sagemaker_args["Tags"] = tags
    # remove args that were passed in for launch but not passed to sagemaker
    sagemaker_args.pop("EcrRepoName", None)
    sagemaker_args.pop("region", None)
    sagemaker_args.pop("profile", None)
    # clear the args that are None so they are not passed
    filtered_args = {k: v for k, v in sagemaker_args.items() if v is not None}
    return filtered_args
---
source: https://docs.wandb.ai/guides/launch/vertex
source_type: web_search
has_code: None
Title: Launch on Vertex | Weights & Biases Documentation - WandB
Description: <strong>Use</strong> <strong>W</strong>&<strong>B</strong> <strong>Launch</strong> <strong>to</strong> send your runs to GCP Vertex. There are two ways <strong>to</strong> <strong>use</strong> <strong>Launch</strong> <strong>on</strong> Vertex:
Bring your own image (BYOI) and push it to your GCP Artifact Registry. Let the W&B Launch agent build a container for you and push it to your Artifact Registry. The following table highlights the key differences between the two workflows listed above:
---
source: https://docs.wandb.ai/guides/launch/setup-launch
source_type: documentation
has_code: True
The launch agent can be configured to build images. You must configure the agent to use a container builder if you intend to use launch jobs created from git repos or code artifacts. See the Create a launch job for more information on how to create a launch job.  
W&B Launch supports two builders:  
* Docker: The Docker builder uses a local Docker daemon to build images.
* Kaniko: Kaniko is a Google project that enables image building in environments where a Docker daemon is unavailable.  
:::tip
Use the Kaniko builder if your agent is polling in an environment where a Docker daemon is unavailable (for example, a Kubernetes cluster).  
See the Set up Kubernetes for details about the Kaniko builder.
:::  
To specify an image builder, include the builder key in your agent configuration. For example, the following code snippet shows a portion of the launch config (`launch-config.yaml`) that specifies to use Docker or Kaniko:  
launch-config.yaml
```
builder:
type: docker | kaniko
```
In some cases, you might want to connect a launch agent to a cloud registry. Common scenarios where you might want to connect a launch agent to a cloud registry include:  
* You want to use the agent to build images and run these images on Amazon SageMaker or VertexAI.
* You want the launch agent to provide credentials to pull from an image repository.  
To learn more about how to configure the agent to interact with a cloud registry, see the Advanced agent set up page.
Activate the launch agent with the `launch-agent` W&B CLI command:  
```
wandb launch-agent -q <queue-1> -q <queue-2> --max-jobs 5
```  
In some use cases, you might want to have a launch agent polling queues from within a Kubernetes cluster. See the Advanced queue set up page for more information.
---
source: https://github.com/wandb/wandb/tree/main/wandb/sdk/launch/builder/build.py
source_type: code
has_code: True
def get_docker_user(launch_project: LaunchProject, runner_type: str) -> Tuple[str, int]:
    import getpass
    username = getpass.getuser()
    if runner_type == "sagemaker" and not launch_project.docker_image:
        # unless user has provided their own image, sagemaker must run as root but keep the name for workdir etc
        return username, 0
    userid = launch_project.docker_user_id or os.geteuid()
    return username, userid
DOCKERFILE_TEMPLATE = """
# ----- stage 1: build -----
FROM {py_build_image} as build
# requirements section depends on pip vs conda, and presence of buildx
ENV PIP_PROGRESS_BAR off
{requirements_section}
# ----- stage 2: base -----
{base_setup}
COPY --from=build /env /env
ENV PATH="/env/bin:$PATH"
ENV SHELL /bin/bash
# some resources (eg sagemaker) must run on root
{user_setup}
WORKDIR {workdir}
RUN chown -R {uid} {workdir}
# make artifacts cache dir unrelated to build
RUN mkdir -p {workdir}/.cache && chown -R {uid} {workdir}/.cache
# copy code/etc
COPY --chown={uid} src/ {workdir}
ENV PYTHONUNBUFFERED=1
{entrypoint_section}
"""
# this goes into base_setup in TEMPLATE
PYTHON_SETUP_TEMPLATE = """
FROM {py_base_image} as base
"""
# this goes into base_setup in TEMPLATE
ACCELERATOR_SETUP_TEMPLATE = """
FROM {accelerator_base_image} as base
# make non-interactive so build doesn't block on questions
ENV DEBIAN_FRONTEND=noninteractive
---
source: https://github.com/wandb/wandb/tree/main/wandb/sdk/launch/loader.py
source_type: code
has_code: True
if not isinstance(environment, AwsEnvironment):
            try:
                environment = AwsEnvironment.from_default()
            except LaunchError as e:
                raise LaunchError(
                    "Could not create Sagemaker runner. "
                    "Environment must be an instance of AwsEnvironment."
                ) from e
        from .runner.sagemaker_runner import SageMakerRunner
        return SageMakerRunner(api, runner_config, environment, registry)
    if runner_name in ["vertex", "gcp-vertex"]:
        from .environment.gcp_environment import GcpEnvironment
        if not isinstance(environment, GcpEnvironment):
            try:
                environment = GcpEnvironment.from_default()
            except LaunchError as e:
                raise LaunchError(
                    "Could not create Vertex runner. "
                    "Environment must be an instance of GcpEnvironment."
                ) from e
        from .runner.vertex_runner import VertexRunner<!--end-context-information-->
<!--start-question-->**Question**: # Query
is there an example of how to use Launch on Sagemaker using BYOI (Bring your own image)?
---
# Query Metadata
Language: en
Intents: 
Product Features:
	The user is asking for a specific example or guide on how to use a Weights & Biases product feature, specifically Launch, in combination with an external service (Sagemaker) using a custom approach (BYOI).
	The query is related to a feature of Weights & Biases such as Sweeps, Artifacts, Reports, Experiments, Tables, Prompts, Launch, Weave, StreamTables and more. Provide a link to the relevant documentation and explain the feature in detail
Sub-queries to consider answering: 
	How to integrate Weights & Biases Launch with Sagemaker?
	What is BYOI (Bring Your Own Image) in the context of Sagemaker?
	Are there any examples of using Weights & Biases Launch with custom images on Sagemaker?
<!--end-question-->
<!--final-answer-in-markdown-->
question
is there an example of how to use Launch on Sagemaker using BYOI (Bring your own image)?
answer
To use Weights & Biases (W&B) Launch on Amazon SageMaker with your own image (BYOI), you need to follow a process that involves preparing your Docker image to be compatible with SageMaker, pushing it to Amazon Elastic Container Registry (ECR), and then configuring W&B Launch to use this image for your training jobs. Here's a step-by-step guide based on the provided documentation:
1. **Prepare Your Docker Image**: Ensure your Docker image is SageMaker compatible. This means it must meet SageMaker's requirements, such as having the necessary entry points for training and serving models. For more information on making your Docker image compatible with SageMaker, refer to the [SageMaker documentation](https://docs.aws.amazon.com/sagemaker/latest/dg/your-algorithms-training-algo.html).
2. **Push Your Image to Amazon ECR**: Once your image is ready and tested locally, push it to your Amazon ECR repository. If you don't have an ECR repository, you'll need to create one. For instructions on how to push your Docker image to ECR, see the [Amazon ECR documentation](https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html).
3. **Configure W&B Launch**: After pushing your image to ECR, you'll need to configure W&B Launch to use this image for your SageMaker training jobs. This involves setting up a launch queue and specifying your ECR image URI in the queue configuration. 
4. **Submit Launch Jobs to SageMaker**: With your queue configured, you can now submit launch jobs to SageMaker using your custom image. This is done by creating a launch job that specifies the ECR image URI and any other necessary configurations for your training job.
While the provided documentation does not include a direct example of using BYOI with W&B Launch on SageMaker, the general steps outlined above are derived from the standard workflow for deploying custom Docker images on SageMaker and integrating external tools like W&B Launch. 
For specific commands and configurations related to W&B Launch, such as creating a launch queue or submitting a launch job, refer to the W&B documentation on [Launch](https://docs.wandb.ai/guides/launch) and the [setup for SageMaker](https://docs.wandb.ai/guides/launch/setup-launch-sagemaker). These resources provide detailed instructions on setting up and using W&B Launch, including how to work with external compute resources like SageMaker.
If you encounter any issues or need further assistance, don't hesitate to reach out to W&B support or consult the W&B community forums for additional help and examples from other users.
model
gpt-4-0125-preview
sources
https://docs.wandb.ai/guides/launch/sagemaker
https://docs.wandb.ai/guides/launch/setup-launch-sagemaker
https://docs.wandb.ai/guides/launch/launch-faqs
https://docs.wandb.ai/guides/launch/setup-launch-sagemaker
https://docs.wandb.ai/guides/launch/setup-launch-sagemaker
https://github.com/wandb/wandb/tree/main/wandb/sdk/launch/runner/sagemaker_runner.py
https://github.com/wandb/wandb/tree/main/wandb/sdk/launch/runner/sagemaker_runner.py
https://github.com/wandb/edu/tree/main/llm-apps-course/docs_sample/getting-started.md
https://docs.wandb.ai/guides/launch
https://docs.wandb.ai/guides/launch/
https://github.com/wandb/wandb/tree/main/wandb/sdk/launch/runner/sagemaker_runner.py
https://docs.wandb.ai/guides/launch/vertex
https://docs.wandb.ai/guides/launch/setup-launch
https://github.com/wandb/wandb/tree/main/wandb/sdk/launch/builder/build.py
https://github.com/wandb/wandb/tree/main/wandb/sdk/launch/loader.py
source_documents
source: https://docs.wandb.ai/guides/launch/sagemaker
source_type: web_search
has_code: None
Title: Launch on SageMaker | Weights & Biases Documentation
Description: <strong>Use</strong> <strong>W</strong>&<strong>B</strong> <strong>Launch</strong> <strong>to</strong> send your runs to AWS <strong>SageMaker</strong>. <strong>There</strong> are two ways <strong>to</strong> <strong>use</strong> <strong>Launch</strong> <strong>on</strong> <strong>SageMaker</strong>:
Bring your own image (BYOI) and push it to your Amazon ECR repository. Let the W&B Launch agent build a container for your and push it to your ECR repository. ... If you bring your own image (1), it must already be SageMaker compatible. If you let W&B build and push the image for you (2), W&B will make your image SageMaker compatible. The following table highlights the key differences between the two workflows listed above:
---
source: https://docs.wandb.ai/guides/launch/setup-launch-sagemaker
source_type: web_search
has_code: None
Title: Set up for SageMaker | Weights & Biases Documentation
Description: You can <strong>use</strong> <strong>W</strong>&<strong>B</strong> <strong>Launch</strong> <strong>to</strong> submit <strong>launch</strong> jobs to Amazon <strong>SageMaker</strong> <strong>to</strong> train machine learning models <strong>using</strong> provided or custom algorithms on <strong>the</strong> <strong>SageMaker</strong> platform. <strong>SageMaker</strong> takes care of spinning up and releasing compute resources, so it can be a good choice for teams without an EKS cluster.
This means that the image you use for training must be stored on ECR. ... This guide shows how to execute SageMaker Training Jobs. For information on how to deploy to models for inference on Amazon SageMaker, see this example Launch job. Before you get started, ensure you satisfy the following prerequisites: Decide if you want the Launch agent to build a Docker image for you.
---
source: https://docs.wandb.ai/guides/launch/launch-faqs
source_type: documentation
has_code: True
Frequently Asked Questions About Launch
Yes. Run the following to launch a pre-built docker image. Replace the items in the `<>` with your information:  
```
wandb launch -d <docker-image-uri> -q <queue-name> -E <entrypoint>
```  
This will build a job when you create a run.  
Or you can make a job from an image:  
```
wandb job create image <image-name> -p <project> -e <entity>
```
1. Create your queue before you start your agent, so that you can set your agent to point to it easily. If you don’t do this, your agent will give errors and not work until you add a queue.
2. Create a W&B service account to start up the agent, so that it's not tied to an individual user account.
3. Use `wandb.config` to read and write your hyperparameters, so that they can be overwritten when re-running a job. Check out this guide if you use argsparse.
Yes. The standard `wandb` CLI includes a `launch` subcommand that you can use to launch your jobs. For more info, try running  
```
wandb launch --help
```
This depends on the environment, we are able to provision resources in SageMaker, and Vertex. In Kubernetes, autoscalers can be used to automatically spin up and spin down resources when required. The Solution Architects at W&B are happy to work with you to configure your underlying Kubernetes infrastructure to facilitate retries, autoscaling, and use of spot instance node pools. Reach out to support@wandb.com or your shared Slack channel.
---
source: https://docs.wandb.ai/guides/launch/setup-launch-sagemaker
source_type: documentation
has_code: False
---
You can use W&B Launch to submit launch jobs to Amazon SageMaker to train machine learning models using provided or custom algorithms on the SageMaker platform.  
Launch jobs sent to Amazon SageMaker are executed as SageMaker Training Jobs with the CreateTrainingJob API. Arguments to the `CreateTrainingJob` API are controlled with the launch queue configuration.  
Amazon SageMaker uses Docker images to execute training jobs. Images pulled by SageMaker must be stored in the Amazon Elastic Container Registry (ECR). This means that the image you use for training must be stored on ECR. To learn more about how to set up Launch with ECR, see Advanced agent set up.  
Amazon SageMaker requires an IAM execution role. The IAM role is used within the SageMaker training job instances to control access to required resources like ECR and Amazon S3. Make note of the IAM role ARN. You will need to specify the IAM role ARN in your queue configuration.
Create and make note of the following AWS resources:  
1. **Setup SageMaker in your AWS account.** See the SageMaker Developer guide for more information.
2. **Create an Amazon ECR repository** to store images you want to execute on Amazon SageMaker. See the Amazon ECR documentation for more information.
3. **Create an Amazon S3 bucket(s)** to store SageMaker inputs and outputs for your SageMaker training jobs. See the Amazon S3 documentation for more information. Make note of the S3 bucket URI and directory.
4. **Create IAM execution role.** The role used in the SageMaker training job requires the following permissions to work. These permissions allow for logging events, pulling from ECR, and interacting with input and output buckets.
IAM role policy
---
source: https://docs.wandb.ai/guides/launch/setup-launch-sagemaker
source_type: documentation
has_code: False
---
You can use W&B Launch to submit launch jobs to Amazon SageMaker to train machine learning models using provided or custom algorithms on the SageMaker platform. SageMaker takes care of spinning up and releasing compute resources, so it can be a good choice for teams without an EKS cluster.  
Launch jobs sent to Amazon SageMaker are executed as SageMaker Training Jobs with the CreateTrainingJob API. Arguments to the `CreateTrainingJob` API are controlled with the launch queue configuration.  
Amazon SageMaker uses Docker images to execute training jobs. Images pulled by SageMaker must be stored in the Amazon Elastic Container Registry (ECR). This means that the image you use for training must be stored on ECR. To learn more about how to set up Launch with ECR, see Advanced agent set up.  
Amazon SageMaker requires an IAM execution role. The IAM role is used within the SageMaker training job instances to control access to required resources like ECR and Amazon S3. Make note of the IAM role ARN. You will need to specify the IAM role ARN in your queue configuration.
Create and make note of the following AWS resources:  
1. **Setup SageMaker in your AWS account.** See the SageMaker Developer guide for more information.
2. **Create an Amazon ECR repository** to store images you want to execute on Amazon SageMaker. See the Amazon ECR documentation for more information.
3. **Create an Amazon S3 buckets** to store SageMaker inputs and outputs for your SageMaker training jobs. See the Amazon S3 documentation for more information. Make note of the S3 bucket URI and directory.
4. **Create IAM execution role.** The role used in the SageMaker training job requires the following permissions to work. These permissions allow for logging events, pulling from ECR, and interacting with input and output buckets. (Note: if you already have this role for SageMaker training jobs, you do not need to create it again.)
IAM role policy
---
source: https://github.com/wandb/wandb/tree/main/wandb/sdk/launch/runner/sagemaker_runner.py
source_type: code
has_code: True
async def launch_sagemaker_job(
    launch_project: LaunchProject,
    sagemaker_args: Dict[str, Any],
    sagemaker_client: "boto3.Client",
    log_client: Optional["boto3.Client"] = None,
) -> SagemakerSubmittedRun:
    training_job_name = sagemaker_args.get("TrainingJobName") or launch_project.run_id
    create_training_job = event_loop_thread_exec(sagemaker_client.create_training_job)
    resp = await create_training_job(**sagemaker_args)
    if resp.get("TrainingJobArn") is None:
        raise LaunchError("Failed to create training job when submitting to SageMaker")
    run = SagemakerSubmittedRun(training_job_name, sagemaker_client, log_client)
    wandb.termlog(
        f"{LOG_PREFIX}Run job submitted with arn: {resp.get('TrainingJobArn')}"
    )
    url = "https://{region}.console.aws.amazon.com/sagemaker/home?region={region}#/jobs/{job_name}".format(
        region=sagemaker_client.meta.region_name, job_name=training_job_name
    )
    wandb.termlog(f"{LOG_PREFIX}See training job status at: {url}")
    return run
---
source: https://github.com/wandb/wandb/tree/main/wandb/sdk/launch/runner/sagemaker_runner.py
source_type: code
has_code: True
class SageMakerRunner(AbstractRunner):
    """Runner class, uses a project to create a SagemakerSubmittedRun."""
    def __init__(
        self,
        api: Api,
        backend_config: Dict[str, Any],
        environment: AwsEnvironment,
        registry: AbstractRegistry,
    ) -> None:
        """Initialize the SagemakerRunner.
        Arguments:
            api (Api): The API instance.
            backend_config (Dict[str, Any]): The backend configuration.
            environment (AwsEnvironment): The AWS environment.
        Raises:
            LaunchError: If the runner cannot be initialized.
        """
        super().__init__(api, backend_config)
        self.environment = environment
        self.registry = registry
    async def run(
        self,
        launch_project: LaunchProject,
        image_uri: str,
    ) -> Optional[AbstractRun]:
        """Run a project on Amazon Sagemaker.
        Arguments:
            launch_project (LaunchProject): The project to run.
        Returns:
            Optional[AbstractRun]: The run instance.
        Raises:
            LaunchError: If the launch is unsuccessful.
        """
        _logger.info("using AWSSagemakerRunner")
---
source: https://github.com/wandb/edu/tree/main/llm-apps-course/docs_sample/getting-started.md
source_type: markdown
has_code: False
---
Follow this guide to get started using W&B Launch. This guide will walk you through the setup of the fundamental components of a launch workflow: a **job**, **launch queue**, and **launch queue**.  
* A **job** is a reusable blueprint for configuring and executing a step of your ML workflow. Jobs can be automatically captured from your workloads when your track those workloads with W&B. In this guide will create and then launch a job that trains a neural network.
* A **launch queue** is a place where you can submit your jobs for execution on a particular compute resource. For example, you might create separate launch queues for submitting jobs that should be run on specific GPU server, or a particular kubernetes cluster. The queue we will create in this guide will be used to submit jobs that will run on your machine via Docker.
* A **launch agent** is a long-running process that polls on one or more launch queues and executes the jobs that it pops from the queue. A launch agent can be started with the `wandb launch-agent` command and is capable on launching jobs onto a multitude of compute platforms, including docker, kubernetes, sagemaker, and more. In this example, you will run a launch agent that will pop jobs from your queue and execute them on its local host using Docker.
Before you get started, ensure you enable the W&B Launch UI and install Docker on the machine where you will run your launch agent.  
See the Docker documentation for more information on how to install Docker, and make sure the docker daemon is running on your machine before you proceed.  
If you want the agent to make use of GPUs, you will also need to install the NVIDIA container toolkit.
---
source: https://docs.wandb.ai/guides/launch
source_type: web_search
has_code: None
Title: Launch - Weights & Biases Documentation - Wandb
Description: Easily scale training runs from your desktop to a compute resource like Amazon <strong>SageMaker</strong>, Kubernetes and more with <strong>W</strong>&<strong>B</strong> <strong>Launch</strong>. <strong>Once</strong> <strong>W</strong>&<strong>B</strong> <strong>Launch</strong> <strong>is</strong> configured, you can quickly run training scripts, model evaluation suites, prepare models for production inference, and more with a few clicks and ...
Based on your use case, you (or someone on your team) will configure the launch queue according to your chosen compute resource target (for example Amazon SageMaker) and deploy a launch agent on your own infrastructure. See the Terms and concepts page for more information on launch jobs, how queues work, launch agents, and additional information on how W&B Launch works. Depending on your use case, explore the following resources to get started with W&B Launch:
---
source: https://docs.wandb.ai/guides/launch/
source_type: documentation
has_code: False
import Translate, {translate} from '@docusaurus/Translate';
Easily scale training runs from your desktop to a compute resource like Amazon SageMaker, Kubernetes and more with W&B Launch. Once W&B Launch is configured, you can quickly run training scripts, model evaluation suites, prepare models for production inference, and more with a few clicks and commands.
Launch is composed of three fundamental components: **launch jobs**, **queues**, and **agents**.  
A *launch job* is a blueprint for configuring and running tasks in your ML workflow. Once you have a launch job, you can add it to a *launch queue*. A launch queue is a first-in, first-out (FIFO) queue where you can configure and submit your jobs to a particular compute target resource, such as Amazon SageMaker or a Kubernetes cluster.  
As jobs are added to the queue, one or more *launch agents* will poll that queue and execute the job on the system targeted by the queue.  
Based on your use case, you (or someone on your team) will configure the launch queue according to your chosen compute resource target (for example Amazon SageMaker) and deploy a launch agent on your own infrastructure.  
See the Terms and concepts page for more information on launch jobs, how queues work, launch agents, and additional information on how W&B Launch works.
Depending on your use case, explore the following resources to get started with W&B Launch:  
* If this is your first time using W&B Launch, we recommend you go through the Walkthrough guide.
* Learn how to set up W&B Launch.
* Create a launch job.
* Check out the W&B Launch public jobs GitHub repo for templates of common tasks like deploying to Triton, evaluating an LLM, or more.
+ View launch jobs created from this repo in this public `wandb/jobs` project W&B project.
---
source: https://github.com/wandb/wandb/tree/main/wandb/sdk/launch/runner/sagemaker_runner.py
source_type: code
has_code: True
if sagemaker_args.get("StoppingCondition") is None:
        raise LaunchError(
            "Sagemaker launcher requires a StoppingCondition Sagemaker resource argument"
        )
    given_env = given_sagemaker_args.get(
        "Environment", sagemaker_args.get("environment", {})
    )
    calced_env = get_env_vars_dict(launch_project, api, max_env_length)
    total_env = {**calced_env, **given_env}
    sagemaker_args["Environment"] = total_env
    # Add wandb tag
    tags = sagemaker_args.get("Tags", [])
    tags.append({"Key": "WandbRunId", "Value": launch_project.run_id})
    sagemaker_args["Tags"] = tags
    # remove args that were passed in for launch but not passed to sagemaker
    sagemaker_args.pop("EcrRepoName", None)
    sagemaker_args.pop("region", None)
    sagemaker_args.pop("profile", None)
    # clear the args that are None so they are not passed
    filtered_args = {k: v for k, v in sagemaker_args.items() if v is not None}
    return filtered_args
---
source: https://docs.wandb.ai/guides/launch/vertex
source_type: web_search
has_code: None
Title: Launch on Vertex | Weights & Biases Documentation - WandB
Description: <strong>Use</strong> <strong>W</strong>&<strong>B</strong> <strong>Launch</strong> <strong>to</strong> send your runs to GCP Vertex. There are two ways <strong>to</strong> <strong>use</strong> <strong>Launch</strong> <strong>on</strong> Vertex:
Bring your own image (BYOI) and push it to your GCP Artifact Registry. Let the W&B Launch agent build a container for you and push it to your Artifact Registry. The following table highlights the key differences between the two workflows listed above:
---
source: https://docs.wandb.ai/guides/launch/setup-launch
source_type: documentation
has_code: True
The launch agent can be configured to build images. You must configure the agent to use a container builder if you intend to use launch jobs created from git repos or code artifacts. See the Create a launch job for more information on how to create a launch job.  
W&B Launch supports two builders:  
* Docker: The Docker builder uses a local Docker daemon to build images.
* Kaniko: Kaniko is a Google project that enables image building in environments where a Docker daemon is unavailable.  
:::tip
Use the Kaniko builder if your agent is polling in an environment where a Docker daemon is unavailable (for example, a Kubernetes cluster).  
See the Set up Kubernetes for details about the Kaniko builder.
:::  
To specify an image builder, include the builder key in your agent configuration. For example, the following code snippet shows a portion of the launch config (`launch-config.yaml`) that specifies to use Docker or Kaniko:  
launch-config.yaml
```
builder:
type: docker | kaniko
```
In some cases, you might want to connect a launch agent to a cloud registry. Common scenarios where you might want to connect a launch agent to a cloud registry include:  
* You want to use the agent to build images and run these images on Amazon SageMaker or VertexAI.
* You want the launch agent to provide credentials to pull from an image repository.  
To learn more about how to configure the agent to interact with a cloud registry, see the Advanced agent set up page.
Activate the launch agent with the `launch-agent` W&B CLI command:  
```
wandb launch-agent -q <queue-1> -q <queue-2> --max-jobs 5
```  
In some use cases, you might want to have a launch agent polling queues from within a Kubernetes cluster. See the Advanced queue set up page for more information.
---
source: https://github.com/wandb/wandb/tree/main/wandb/sdk/launch/builder/build.py
source_type: code
has_code: True
def get_docker_user(launch_project: LaunchProject, runner_type: str) -> Tuple[str, int]:
    import getpass
    username = getpass.getuser()
    if runner_type == "sagemaker" and not launch_project.docker_image:
        # unless user has provided their own image, sagemaker must run as root but keep the name for workdir etc
        return username, 0
    userid = launch_project.docker_user_id or os.geteuid()
    return username, userid
DOCKERFILE_TEMPLATE = """
# ----- stage 1: build -----
FROM {py_build_image} as build
# requirements section depends on pip vs conda, and presence of buildx
ENV PIP_PROGRESS_BAR off
{requirements_section}
# ----- stage 2: base -----
{base_setup}
COPY --from=build /env /env
ENV PATH="/env/bin:$PATH"
ENV SHELL /bin/bash
# some resources (eg sagemaker) must run on root
{user_setup}
WORKDIR {workdir}
RUN chown -R {uid} {workdir}
# make artifacts cache dir unrelated to build
RUN mkdir -p {workdir}/.cache && chown -R {uid} {workdir}/.cache
# copy code/etc
COPY --chown={uid} src/ {workdir}
ENV PYTHONUNBUFFERED=1
{entrypoint_section}
"""
# this goes into base_setup in TEMPLATE
PYTHON_SETUP_TEMPLATE = """
FROM {py_base_image} as base
"""
# this goes into base_setup in TEMPLATE
ACCELERATOR_SETUP_TEMPLATE = """
FROM {accelerator_base_image} as base
# make non-interactive so build doesn't block on questions
ENV DEBIAN_FRONTEND=noninteractive
---
source: https://github.com/wandb/wandb/tree/main/wandb/sdk/launch/loader.py
source_type: code
has_code: True
if not isinstance(environment, AwsEnvironment):
            try:
                environment = AwsEnvironment.from_default()
            except LaunchError as e:
                raise LaunchError(
                    "Could not create Sagemaker runner. "
                    "Environment must be an instance of AwsEnvironment."
                ) from e
        from .runner.sagemaker_runner import SageMakerRunner
        return SageMakerRunner(api, runner_config, environment, registry)
    if runner_name in ["vertex", "gcp-vertex"]:
        from .environment.gcp_environment import GcpEnvironment
        if not isinstance(environment, GcpEnvironment):
            try:
                environment = GcpEnvironment.from_default()
            except LaunchError as e:
                raise LaunchError(
                    "Could not create Vertex runner. "
                    "Environment must be an instance of GcpEnvironment."
                ) from e
        from .runner.vertex_runner import VertexRunner
total_tokens
8,739
prompt_tokens
7,939
completion_tokens
800
time_taken
33.804854
start_time
datetime.datetime(2024, 9, 6, 11, 47, 34, 523883, tzinfo=datetime.timezone.utc)
end_time
datetime.datetime(2024, 9, 6, 11, 48, 8, 329765, tzinfo=datetime.timezone.utc)