### Example: Get first 50 data points for loss metric Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Demonstrates fetching the first N data points for a scalar metric. ```bash # Get first 50 data points swanlab api run metrics PATH --keys loss --range-head 50 ``` -------------------------------- ### Install from Source - Method 2 Source: https://github.com/swanhubx/swanlab/blob/main/README_EN.md Install SwanLab from source code using pip install git+. ```bash pip install git+https://github.com/SwanHubX/SwanLab.git ``` -------------------------------- ### Example: Get steps 100–200 for loss metric Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Demonstrates fetching scalar metric data for a specific range of steps. ```bash # Get steps 100–200 swanlab api run metrics PATH --keys loss --range-start 100 --range-end 200 ``` -------------------------------- ### Example: Get data by timestamp range Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Demonstrates fetching scalar metric data within a specific timestamp range. ```bash # Get data by timestamp range (Unix milliseconds) swanlab api run metrics PATH --keys loss --range-type timestamp --range-start 1714368000000 --range-end 1714454400000 ``` -------------------------------- ### Install from Source - Method 1 Source: https://github.com/swanhubx/swanlab/blob/main/README_EN.md Install SwanLab from source code using git clone. ```bash git clone https://github.com/SwanHubX/SwanLab.git pip install -e . ``` -------------------------------- ### Install SwanLab Source: https://github.com/swanhubx/swanlab/blob/main/README_EN.md Install SwanLab using pip. ```bash pip install swanlab ``` -------------------------------- ### Dashboard Extension Installation Source: https://github.com/swanhubx/swanlab/blob/main/README_EN.md Install the SwanLab dashboard extension. ```bash pip install 'swanlab[dashboard]' ``` -------------------------------- ### Project Info Command Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Get project details by path. ```bash swanlab api project info PATH [--save [FILENAME]] [--host HOST] [--api-key KEY] ``` -------------------------------- ### Get Self-Hosted Instance Info Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Shows information about the self-hosted Swanlab instance. ```bash swanlab api selfhosted info [--save [FILENAME]] [--host HOST] [--api-key KEY] ``` -------------------------------- ### Experiment Info Command Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Get experiment details. ```bash swanlab api run info PATH [--save [FILENAME]] [--host HOST] [--api-key KEY] ``` -------------------------------- ### Filter by State Example Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/references/SWANLAB_CONCEPTS.md Example of filtering experiments that are in either 'FINISHED' or 'RUNNING' states. ```json [{"key": "state", "type": "STABLE", "op": "IN", "value": ["FINISHED", "RUNNING"]}] ``` -------------------------------- ### Filter by Config Value Example Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/references/SWANLAB_CONCEPTS.md Example of filtering experiments based on a specific configuration value, such as 'learning_rate'. ```json [{"key": "learning_rate", "type": "CONFIG", "op": "EQ", "value": ["0.01"]}] ``` -------------------------------- ### Filter by Time Range (Finished At) Example Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/references/SWANLAB_CONCEPTS.md Example of filtering experiments that finished after a specific date and time. ```json [{"key": "finishedAt", "type": "STABLE", "op": "GTE", "value": ["2026-04-01T00:00:00"]}] ``` -------------------------------- ### Multiple Filters Combined Example Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/references/SWANLAB_CONCEPTS.md Demonstrates combining multiple filters for state, configuration, and scalar metrics. ```json [ {"key": "state", "type": "STABLE", "op": "EQ", "value": ["FINISHED"]}, {"key": "learning_rate", "type": "CONFIG", "op": "GTE", "value": ["0.001"]}, {"key": "train/loss", "type": "SCALAR", "op": "LTE", "value": ["0.5"]} ] ``` -------------------------------- ### Workspace Info Command Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Get workspace details for a given username. ```bash swanlab api workspace info USERNAME [--save [FILENAME]] [--host HOST] [--api-key KEY] ``` -------------------------------- ### Swanlab API Run Column Command Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Gets a single column by key name. ```bash swanlab api run column PATH --key KEY [OPTIONS] ``` -------------------------------- ### Filter by Scalar Metric Example Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/references/SWANLAB_CONCEPTS.md Example of filtering experiments based on a scalar metric value, such as 'train/loss'. ```json [{"key": "train/loss", "type": "SCALAR", "op": "LTE", "value": ["0.5"]}] ``` -------------------------------- ### Time Range Query Example Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/references/SWANLAB_CONCEPTS.md Demonstrates how to filter experiments within a specific time range using GTE and LTE operators on the 'createdAt' field. ```json [ {"key": "createdAt", "type": "STABLE", "op": "GTE", "value": ["2026-01-01T00:00:00"]}, {"key": "createdAt", "type": "STABLE", "op": "LTE", "value": ["2026-04-29T23:59:59"]} ] ``` -------------------------------- ### Get Media Data Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Retrieves media data (images, audio, etc.) for specified keys from an experiment, optionally for a specific step or all steps. ```bash swanlab api run medias PATH --keys KEYS [OPTIONS] ``` -------------------------------- ### User Info Command Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Get the currently authenticated user's profile. ```bash swanlab api user info [--save [FILENAME]] [--host HOST] [--api-key KEY] ``` -------------------------------- ### Get Console Logs Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Retrieves console logs captured during a run, with options for offset, log level, and timestamp stripping. ```bash swanlab api run logs PATH [OPTIONS] ``` -------------------------------- ### Get Scalar Metric Data Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Retrieves scalar metric data for specified keys from an experiment. Supports sampling, timestamp stripping, and range filtering. ```bash swanlab api run metrics PATH --keys KEYS [OPTIONS] ``` -------------------------------- ### Integrate SwanLab with Your Code Source: https://github.com/swanhubx/swanlab/blob/main/README_EN.md Initialize a SwanLab experiment and log metrics. ```python import swanlab # Initialize a new SwanLab experiment swanlab.init( project="my-first-ml", config={'learning-rate': 0.003}, ) # Log metrics for i in range(10): swanlab.log({"loss": i, "acc": i}) ``` -------------------------------- ### Project Create Command Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Create a new project. ```bash swanlab api project create -n NAME [OPTIONS] ``` -------------------------------- ### System Summary Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Shows system usage summary for the self-hosted instance, including aggregate statistics. This command is restricted to root users. ```bash swanlab api selfhosted summary [--save [FILENAME]] [--host HOST] [--api-key KEY] ``` -------------------------------- ### Swanlab API Run Columns Command Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Lists columns (metric definitions) under an experiment. ```bash swanlab api run columns PATH [OPTIONS] ``` -------------------------------- ### Create User in Self-Hosted Instance Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Creates a new user in the self-hosted Swanlab instance. Requires root privileges. ```bash swanlab api selfhosted create-user -u USERNAME -p PASSWORD ``` -------------------------------- ### SwanLab Login Source: https://github.com/swanhubx/swanlab/blob/main/README_EN.md Log in to SwanLab using the CLI and provide an API key. ```bash swanlab login ``` -------------------------------- ### Project List Command Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md List projects under a workspace. Paginated by default. ```bash swanlab api project list [OPTIONS] ``` -------------------------------- ### List Projects Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Lists all projects across the self-hosted instance. This command is restricted to root users and supports filtering by creator, workspace, and keyword search. ```bash swanlab api selfhosted list-projects [OPTIONS] ``` -------------------------------- ### Experiment List Command Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md List experiments under a project. Paginated by default. ```bash swanlab api run list -p PROJECT_PATH [OPTIONS] ``` -------------------------------- ### List Workspaces Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Lists all workspaces in the self-hosted instance. This command is restricted to root users and supports filtering by search keyword. ```bash swanlab api selfhosted list-workspaces [OPTIONS] ``` -------------------------------- ### List Users Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Lists users in the self-hosted instance. This command is restricted to root users. ```bash swanlab api selfhosted list-users [OPTIONS] ``` -------------------------------- ### Swanlab API Run Filter Command Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/SKILL.md Filters experiments under a project by a structured query. Returns matching experiments without pagination. ```bash swanlab api run filter -p PROJECT_PATH -f FILTER_QUERY [--save [FILENAME]] [--host HOST] [--api-key KEY] ``` ```bash # Filter by state swanlab api run filter -p user/project -f '[{"key":"state","type":"STABLE","op":"EQ","value":["FINISHED"]}]' ``` ```bash # Filter by config value swanlab api run filter -p user/project -f '[{"key":"learning_rate","type":"CONFIG","op":"GTE","value":["0.001"]}]' ``` ```bash # Filter by time range — filter values are UTC+8, response timestamps are UTC swanlab api run filter -p user/project -f [ {"key":"createdAt","type":"STABLE","op":"GTE","value":["2026-01-01T00:00:00"]}, {"key":"createdAt","type":"STABLE","op":"LTE","value":["2026-04-29T23:59:59"]} ] ``` ```bash # From a JSON file swanlab api run filter -p user/project -f ./filters.json ``` ```bash # Multiple filters combined swanlab api run filter -p user/project -f [ {"key":"state","type":"STABLE","op":"IN","value":["FINISHED","RUNNING"]}, {"key":"learning_rate","type":"CONFIG","op":"EQ","value":["0.01"]} ] ``` -------------------------------- ### SwanLab README Badge Source: https://github.com/swanhubx/swanlab/blob/main/README_EN.md Badges to add to your README to indicate SwanLab usage. ```markdown [![](https://raw.githubusercontent.com/SwanHubX/assets/main/badge2.svg)](your experiment url) [![](https://raw.githubusercontent.com/SwanHubX/assets/main/badge1.svg)](your experiment url) ``` -------------------------------- ### Directory Structure Source: https://github.com/swanhubx/swanlab/blob/main/protos/README.md The directory structure of the protos directory, outlining the organization of Protobuf definitions. ```protobuf protos/ └── swanlab/ ├── record/ │ └── v1/ │ └── record.proto # Top-level envelope Record │ ├── run/ │ └── v1/ │ └── run.proto # Run lifecycle (StartRecord, FinishRecord, RunState, ResumeMode) │ ├── metric/ │ ├── column/ │ │ └── v1/ │ │ └── column.proto # Column definition (ColumnRecord), describing metric display and categorization configuration │ └── data/ │ └── v1/ │ └── data.proto # Metric data (ScalarRecord, MediaRecord) │ ├── config/ │ └── v1/ │ └── config.proto # Experiment configuration reference (ConfigRecord, UpdateType) │ ├── env/ │ └── v1/ │ └── env.proto # Software environment and host metadata reference (MetadataRecord, RequirementsRecord, CondaRecord) │ ├── terminal/ │ └── v1/ │ └── log.proto # Terminal proxy captured stdout/stderr output (LogRecord, LogLevel) │ ├── save/ │ └── v1/ │ └── save.proto # File save record (SaveRecord, SavePolicy) │ ├── settings/ │ ├── core/ │ │ └── v1/ │ │ └── core.proto # Core synchronization service configuration (CoreSettings) │ └── probe/ │ └── v1/ │ └── probe.proto # Probe hardware acquisition service configuration (ProbeSettings) │ └── grpc/ ├── core/ │ ├── v1/ │ │ ├── core.proto # CoreService gRPC service (receives experiment records) │ │ └── sync.proto # CoreSyncService gRPC service (starts log synchronization) │ └── ... └── probe/ └── v1/ └── probe.proto # ProbeService gRPC service (starts hardware acquisition) ``` -------------------------------- ### Citing SwanLab in Papers Source: https://github.com/swanhubx/swanlab/blob/main/README_EN.md BibTeX entry for citing SwanLab in academic papers. ```bibtex @software{Zeyilin_SwanLab_2023, author = {Zeyi Lin, Shaohong Chen, Kang Li, Qiushan Jiang, Zirui Cai, Kaifang Ji and {The SwanLab team}}, doi = {10.5281/zenodo.11100550}, license = {Apache-2.0}, title = {{SwanLab}}, url = {https://github.com/swanhubx/swanlab}, year = {2023} } ``` -------------------------------- ### Message Flow Source: https://github.com/swanhubx/swanlab/blob/main/protos/README.md Illustrates the sequence of messages generated during a SwanLab run, from initialization to completion. ```protobuf swanlab.init(...) → Record { start: StartRecord } # Run basic information, written once → Record { metadata: MetadataRecord } # Host and environment snapshot reference, written once → Record { requirements: RequirementsRecord } # Python dependency reference, written once → Record { conda: CondaRecord } # Conda environment reference, written once → Record { config: ConfigRecord } # Experiment config (INIT), written once # When a key first appears in the training loop, send column definition first → Record { column: ColumnRecord { key="loss", type=SCALAR, ... } } → Record { column: ColumnRecord { key="img", type=IMAGE, ... } } # Each metric generates a separate Record, swanlab.log({"loss": 0.5, "img": Image(...)}, step=10) generates two: → Record { scalar: ScalarRecord { key="loss", step=10, ... } } → Record { media: MediaRecord { key="img", step=10, ... } } # Terminal proxy (per line) → Record { log: LogRecord { line="...", level=INFO } } # Config update during run → Record { config: ConfigRecord { update_type=PATCH, ... } } # File save → Record { save: SaveRecord { name="...", policy=NOW } } swanlab.finish() → Record { finish: FinishRecord { state=FINISHED } } ``` -------------------------------- ### Path Convention Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/references/SWANLAB_CONCEPTS.md API path format for addressing SwanLab entities. ```markdown username → Workspace username/project_name → Project username/project_name/run_id → Experiment ``` -------------------------------- ### Media Metrics Data Structure Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/references/SWANLAB_CONCEPTS.md Structure for media metrics, including available steps and URLs for media items. ```json Structure: { "steps": [0, 1, 2], // available steps "step": 0, // current step "metrics": [ { "index": 0, "items": [ { "url": "https://..." } // presigned download URL ] } ] } ``` -------------------------------- ### Core Entity Hierarchy Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/references/SWANLAB_CONCEPTS.md Diagram illustrating the hierarchical relationship between SwanLab entities. ```markdown User (authenticated account) +-- Workspace (personal or team namespace, identified by username) | +-- Project (groups related experiments) | | +-- Experiment / Run (a single training execution) | | | +-- Config (input hyperparameters, set at init, immutable) | | | +-- Column (a metric definition — e.g. "loss", "acc", "image") | | | | +-- Scalar Metrics (time-series numeric data) | | | | +-- Media Metrics (images, audio, video, molecules, etc.) | | | +-- Console Logs (captured stdout/stderr output) | | | +-- Profile (metadata: config, requirements, conda, hardware) ``` -------------------------------- ### Console Logs Data Structure Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/references/SWANLAB_CONCEPTS.md Structure of a single log entry for console logs. ```json Structure per log entry: { "epoch": 0, // shard index (logs are paginated by shards) "level": "INFO", // DEBUG | INFO | WARN | ERROR "message": "Epoch 1/10", "tag": "", // optional tag "timestamp": "..." // ISO timestamp } ``` -------------------------------- ### Experiment Profile Structure Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/references/SWANLAB_CONCEPTS.md Structure of the experiment profile object containing metadata about the run. ```json { "config": { ... }, // Hyperparameters set at swanlab.init(config={...}) "metadata": { ... }, // Hardware & environment info (auto-collected) "requirements": "...", // pip requirements string "conda": "..." // conda environment YAML } ``` -------------------------------- ### Scalar Metrics Data Structure Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/references/SWANLAB_CONCEPTS.md Structure of a single data point for scalar metrics. ```json Structure per data point: { "index": 0, // step number or custom x-axis value "data": 0.523, // the metric value (can be int, float, or "NaN"/"INF"/"-INF") "timestamp": 1714368000 // Unix timestamp } ``` -------------------------------- ### Filter Object Structure Source: https://github.com/swanhubx/swanlab/blob/main/skills/swanlab-skill/references/SWANLAB_CONCEPTS.md Structure of a filter object for experiment filtering. ```json { "key": "state", "type": "STABLE", "op": "EQ", "value": ["FINISHED"] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.