### Setup Beta9 SDK Source: https://github.com/beam-cloud/beta9/blob/main/CONTRIBUTING.md Run this command to set up the Beta9 SDK. Ensure you have Python 3.8 or higher installed. ```bash make setup-sdk ``` -------------------------------- ### Setup On-Prem Agent Source: https://github.com/beam-cloud/beta9/blob/main/docs/opa/README.md Create a machine within a worker pool and obtain a setup command to install the agent. This command registers the machine with Beam's control plane and joins the Tailscale network. ```sh $ beam machine create --pool my-h100-pool => Created machine with ID: 'c11d3030'. Use the following command to setup the node: # -- Agent setup sudo curl -L -o agent https://release.beam.cloud/agent/agent && \ sudo chmod +x agent && \ sudo ./agent --token "MY_TOKEN" \ --machine-id "c11d3030" \ --tailscale-url "" \ --tailscale-auth "tskey-auth" \ --pool-name "my-h100-pool" \ --provider-name "generic" ``` -------------------------------- ### Setup Beta9 Server Locally Source: https://github.com/beam-cloud/beta9/blob/main/CONTRIBUTING.md Run this command to set up the Beta9 server for local development using k3d. Ensure Docker is installed. ```bash make setup ``` -------------------------------- ### Install Beam Client Source: https://github.com/beam-cloud/beta9/blob/main/README.md Install the Beam client library using pip. This is the first step to using Beam for your AI workloads. ```shell pip install beam-client ``` -------------------------------- ### Install Dependencies with Poetry Source: https://github.com/beam-cloud/beta9/blob/main/sdk/bin/docgen.md Install all project dependencies, including development dependencies, using Poetry. ```sh poetry install ``` -------------------------------- ### Monitor Setup Logs via SSH Source: https://github.com/beam-cloud/beta9/blob/main/deploy/crusoe/README.md Connect to your deployed instance via SSH to monitor the user-data log in real-time. Replace `` with the actual IP address of your instance. ```sh ssh -i ~/.ssh/id_crusoecloud ubuntu@ 'tail -n+1 -f /var/log/user-data.log' ``` -------------------------------- ### Fix Permissions for /usr/local/bin Source: https://github.com/beam-cloud/beta9/blob/main/CONTRIBUTING.md If you encounter permission errors during setup, use this command to change the ownership of the /usr/local/bin directory to your current user. ```bash sudo chown $(whoami) /usr/local/bin ``` -------------------------------- ### Configure Local DNS with Dnsmasq Source: https://github.com/beam-cloud/beta9/blob/main/CONTRIBUTING.md Install and configure dnsmasq for local DNS resolution, required for external file services and optional for subdomain middleware. This setup directs 'cluster.local' domain traffic to 127.0.0.1. ```shell brew install dnsmasq echo 'address=/cluster.local/127.0.0.1' >> /opt/homebrew/etc/dnsmasq.conf sudo bash -c 'mkdir -p /etc/resolver' sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/cluster.local' sudo brew services start dnsmasq ``` -------------------------------- ### Deploy Serverless Inference Endpoint Source: https://github.com/beam-cloud/beta9/blob/main/README.md Create an autoscaling endpoint for your custom AI model. This example configures the image, GPU, CPU, memory, and autoscaling parameters. ```python from beam import Image, endpoint from beam import QueueDepthAutoscaler @endpoint( image=Image(python_version="python3.11"), gpu="A10G", cpu=2, memory="16Gi", autoscaler=QueueDepthAutoscaler(max_containers=5, tasks_per_container=30) ) def handler(): return {"label": "cat", "confidence": 0.97} ``` -------------------------------- ### Run Background Tasks with Beam Source: https://github.com/beam-cloud/beta9/blob/main/README.md Schedule resilient background tasks using a simple decorator. This example defines input schema, task policy, and demonstrates invoking a background task. ```python from beam import Image, TaskPolicy, schema, task_queue class Input(schema.Schema): image_url = schema.String() @task_queue( name="image-processor", image=Image(python_version="python3.11"), cpu=1, memory=1024, inputs=Input, task_policy=TaskPolicy(max_retries=3), ) def my_background_task(input: Input, *, context): image_url = input.image_url print(f"Processing image: {image_url}") return {"image_url": image_url} if __name__ == "__main__": # Invoke a background task from your app (without deploying it) my_background_task.put(image_url="https://example.com/image.jpg") # You can also deploy this behind a versioned endpoint with: # beam deploy app.py:my_background_task --name image-processor ``` -------------------------------- ### List Machines Source: https://github.com/beam-cloud/beta9/blob/main/docs/opa/README.md View all registered machines in your inventory, including their hardware specifications, status, and assigned worker pool. This helps in verifying the setup and availability of your on-prem resources. ```sh $ beam machine list | ID | CPU | Memory | GPU | Status | Pool | |----------|---------|------------|---------|------------|--------------| | edc9c2d2 | 30,000m | 222.16 GiB | H100 | registered | my-h100-pool | ``` -------------------------------- ### Launch and Deploy fly App Source: https://github.com/beam-cloud/beta9/blob/main/deploy/fly-io/README.md Initiate the deployment of the fly app, which includes copying configuration and prompting for confirmation. This command modifies the fly.toml file in-place. ```shell fly launch --org my-org --name my-deployment --no-deploy --copy-config --yes ``` -------------------------------- ### Create a Sandbox Environment Source: https://github.com/beam-cloud/beta9/blob/main/README.md Spin up isolated containers to run LLM-generated code. This snippet demonstrates creating a sandbox and running code within it. ```python from beam import Image, Sandbox sandbox = Sandbox(image=Image()).create() response = sandbox.process.run_code("print('I am running remotely')") print(response.result) ``` -------------------------------- ### Initialize and Apply Terraform Configuration Source: https://github.com/beam-cloud/beta9/blob/main/deploy/crusoe/README.md Run these commands to initialize your Terraform working directory and apply the configuration to deploy resources on Crusoe Cloud. ```sh terraform init ``` ```sh terraform apply ``` -------------------------------- ### Generate All Protocol Buffers and OpenAPI Schemas Source: https://github.com/beam-cloud/beta9/blob/main/docs/openapi/README.md Execute this command to regenerate all protocol buffers, including the OpenAPI schemas. ```bash make protocol ``` -------------------------------- ### Import Secrets and Deploy Application Source: https://github.com/beam-cloud/beta9/blob/main/deploy/fly-io/README.md Import the previously prepared secrets into the fly.io environment, deploy the application, and scale it to a single instance in the 'iad' region. Ensure the max instances per region is set to 1. ```shell cat .env | fly secrets import ``` ```shell fly deploy ``` ```shell fly scale count 1 --max-per-region=1 --region=iad ``` -------------------------------- ### Generate SDK Reference Markdown Source: https://github.com/beam-cloud/beta9/blob/main/sdk/bin/docgen.md Run the docgen script to generate markdown for the SDK Reference documentation. On macOS, the output can be piped to pbcopy for immediate use. ```sh # Generates markdown ./bin/docgen.py ``` ```sh # Generates markdown and copies to your clipboard (on macOS) ./bin/docgen.py | pbcopy ``` -------------------------------- ### List Available Crusoe Compute Instance Types Source: https://github.com/beam-cloud/beta9/blob/main/deploy/crusoe/README.md Use this CLI command to view the available instance types for deployment on Crusoe Cloud. This is useful for selecting the appropriate `instance_type` input. ```sh crusoe compute vms types ``` -------------------------------- ### Generate OpenAPI Schemas Source: https://github.com/beam-cloud/beta9/blob/main/docs/openapi/README.md Run this command to regenerate the OpenAPI schemas from the proto files. ```bash make openapi ``` -------------------------------- ### Define and Run a Function with Beta9 SDK Source: https://github.com/beam-cloud/beta9/blob/main/sdk/README.md Define a Python function decorated with `@function` to run on Beta9. Use `.map()` to invoke the function multiple times with different inputs. Ensure the `main` function is called when the script is executed directly. ```python from beta9 import function @function( cpu=0.25, gpu="L4", ) def square(i: int): return i**2 def main(): numbers = list(range(10)) squared = [] for result in square.map(numbers): squared.append(result) print("numbers:", numbers) print("squared:", sorted(squared)) if __name__ == "__main__": main() ``` -------------------------------- ### Prepare Secrets for JuiceFS S3 Gateway Source: https://github.com/beam-cloud/beta9/blob/main/deploy/fly-io/README.md Create a .env file to store secrets required by the JuiceFS S3 Gateway application. Ensure all sensitive information is correctly formatted. ```shell cat <<'EOF' | tee > .env TAILSCALE_AUTHKEY="my-tailscale-authkey" JUICEFS_NAME="my-filesystem" JUICEFS_REDIS_URI="rediss://username:password@hostname:6379/0" JUICEFS_BUCKET="https://fly.storage.tigris.dev/my-bucket-name" JUICEFS_ACCESS_KEY="my-access-key" JUICEFS_SECRET_KEY="my-secret-key" MINIO_ROOT_USER="my-username" MINIO_ROOT_PASSWORD="my-password" EOF ``` -------------------------------- ### Configure Beta9 Gateway for Host-Based URLs Source: https://github.com/beam-cloud/beta9/blob/main/CONTRIBUTING.md Add this configuration to your Beta9 settings to enable host-based URLs, which is necessary for using subdomain middleware. ```yaml gateway: invokeURLType: host ``` -------------------------------- ### Create a Worker Pool Source: https://github.com/beam-cloud/beta9/blob/main/docs/opa/README.md Use the CLI to create a new worker pool with specified attributes like GPU type and count. This defines a group of workers for specific tasks. ```sh beam pool create --name my-h100-pool --gpu-type A100 --default-gpu-count 1 ``` -------------------------------- ### Beta9 Örnek Uygulama Source: https://github.com/beam-cloud/beta9/blob/main/docs/tr/README.md Bir tamsayıyı karekökleyen bir fonksiyon tanımlar ve bunu bir listedeki her öğe için uzak bir kapsayıcıda çalıştırır. ```python from beta9 import function @function(cpu=8) def square(i: int): return i**2 def main(): numbers = list(range(10)) squared = [] # Listedeki her öğe için uzak bir kapsayıcı çalıştır for result in square.map(numbers): squared.append(result) ``` -------------------------------- ### List Available Crusoe Cloud Locations Source: https://github.com/beam-cloud/beta9/blob/main/deploy/crusoe/README.md Execute this command to see the list of available deployment locations on Crusoe Cloud. This helps in setting the `location` input for your Terraform configuration. ```sh crusoe locations list ``` -------------------------------- ### Run Function on Worker Pool Source: https://github.com/beam-cloud/beta9/blob/main/docs/opa/README.md Define and run a Python function that will be executed on your on-prem worker pool. Specify hardware requirements like GPU type using the `@function` decorator. ```python from beam import function @function(gpu="H100") def handler(): return {"message": "This is running on your worker pool!"} if __name__ == "__main__": handler.remote() ``` -------------------------------- ### Terraform Variables for Crusoe Cloud Deployment Source: https://github.com/beam-cloud/beta9/blob/main/deploy/crusoe/README.md Define the path to your SSH public key for instance access. Ensure this key is generated or available before applying Terraform. ```hcl ssh_key_path = "~/.ssh/id_crusoecloud.pub" ``` -------------------------------- ### Remote Function Execution with Beta9 Source: https://github.com/beam-cloud/beta9/blob/main/docs/it/README.md This Python code defines a remote function 'square' that computes the square of an integer and then maps this function over a list of numbers, executing each call in a remote container. ```python from beta9 import function @function(cpu=8) def square(i: int): return i**2 def main(): numbers = list(range(10)) squared = [] # Esegui un contenitore remoto per ogni elemento nell'elenco for result in square.map(numbers): squared.append(result) ``` -------------------------------- ### Destroy fly.io Deployment Source: https://github.com/beam-cloud/beta9/blob/main/deploy/fly-io/README.md Remove the deployed application from fly.io. This command will prompt for confirmation before proceeding with the destruction. ```shell fly app destroy --yes my-deployment ``` -------------------------------- ### Check Beta9 Gateway Health Source: https://github.com/beam-cloud/beta9/blob/main/CONTRIBUTING.md Use curl to check the health of your local k3s instance via the Beta9 gateway using its internal service domain. ```shell curl http://beta9-gateway.beta9.svc.cluster.local:1994/api/v1/health ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.