Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/aiperf/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys

from aiperf.cli import app
from aiperf.gpu_telemetry.constants import DEFAULT_DCGM_ENDPOINTS
from aiperf.common.environment import Environment


def main() -> int:
Expand All @@ -15,7 +15,7 @@ def main() -> int:
if "--gpu-telemetry" in sys.argv:
idx = sys.argv.index("--gpu-telemetry")
if idx >= len(sys.argv) - 1 or sys.argv[idx + 1].startswith("-"):
for endpoint in reversed(DEFAULT_DCGM_ENDPOINTS):
for endpoint in reversed(Environment.GPU.DEFAULT_DCGM_ENDPOINTS):
sys.argv.insert(idx + 1, endpoint)
return app(sys.argv[1:])

Expand Down
21 changes: 21 additions & 0 deletions src/aiperf/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def raise_startup_error_and_exit(
border_style=border_style,
)
)
console.file.flush()

sys.exit(exit_code)

Expand Down Expand Up @@ -115,3 +116,23 @@ def __exit__(self, exc_type, exc_value, traceback):
title=self.title,
exit_code=self.exit_code,
)


def print_developer_mode_warning() -> None:
"""Print a warning message to the console if developer mode is enabled."""
from rich.console import Console
from rich.panel import Panel
from rich.text import Text

console = Console()
panel = Panel(
Text(
"Developer Mode is active. This is a developer-only feature. Use at your own risk.",
style="yellow",
),
title="AIPerf Developer Mode",
border_style="bold yellow",
title_align="left",
)
console.print(panel)
console.file.flush()
12 changes: 4 additions & 8 deletions src/aiperf/common/base_component_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@

from aiperf.common.base_service import BaseService
from aiperf.common.config import ServiceConfig, UserConfig
from aiperf.common.constants import (
DEFAULT_HEARTBEAT_INTERVAL,
DEFAULT_MAX_REGISTRATION_ATTEMPTS,
DEFAULT_REGISTRATION_INTERVAL,
)
from aiperf.common.decorators import implements_protocol
from aiperf.common.enums import CommandType, LifecycleState, ServiceType
from aiperf.common.environment import Environment
from aiperf.common.hooks import (
background_task,
on_command,
Expand Down Expand Up @@ -57,7 +53,7 @@ def __init__(
**kwargs,
)

@background_task(interval=DEFAULT_HEARTBEAT_INTERVAL, immediate=False)
@background_task(interval=Environment.SERVICE.HEARTBEAT_INTERVAL, immediate=False)
async def _heartbeat_task(self) -> None:
"""Send a heartbeat notification to the system controller."""
await self.publish(
Expand All @@ -83,12 +79,12 @@ async def _register_service_on_start(self) -> None:
target_service_type=ServiceType.SYSTEM_CONTROLLER,
state=self.state,
)
for _ in range(DEFAULT_MAX_REGISTRATION_ATTEMPTS):
for _ in range(Environment.SERVICE.REGISTRATION_MAX_ATTEMPTS):
result = await self.send_command_and_wait_for_response(
# NOTE: We keep the command id the same each time to ensure that the system controller
# can ignore duplicate registration requests.
command_message,
timeout=DEFAULT_REGISTRATION_INTERVAL,
timeout=Environment.SERVICE.REGISTRATION_INTERVAL,
)
if isinstance(result, CommandResponse):
self.debug(
Expand Down
7 changes: 4 additions & 3 deletions src/aiperf/common/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys

from aiperf.common.config import ServiceConfig, UserConfig
from aiperf.common.environment import Environment
from aiperf.common.protocols import ServiceProtocol


Expand Down Expand Up @@ -52,7 +53,7 @@ def bootstrap_and_run_service(
user_config = load_user_config()

async def _run_service():
if service_config.developer.enable_yappi:
if Environment.DEV.ENABLE_YAPPI:
_start_yappi_profiling()

from aiperf.module_loader import ensure_modules_loaded
Expand Down Expand Up @@ -114,11 +115,11 @@ async def _run_service():
except Exception as e:
service.exception(f"Unhandled exception in service: {e}")

if service_config.developer.enable_yappi:
if Environment.DEV.ENABLE_YAPPI:
_stop_yappi_profiling(service.service_id, user_config)

with contextlib.suppress(asyncio.CancelledError):
if not service_config.developer.disable_uvloop:
if not Environment.SERVICE.DISABLE_UVLOOP:
import uvloop

uvloop.run(_run_service())
Expand Down
10 changes: 0 additions & 10 deletions src/aiperf/common/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@
)
from aiperf.common.config.cli_parameter import (
CLIParameter,
DeveloperOnlyCLI,
DisableCLI,
)
from aiperf.common.config.config_defaults import (
AudioDefaults,
CLIDefaults,
ConversationDefaults,
DevDefaults,
EndpointDefaults,
ImageDefaults,
InputDefaults,
Expand Down Expand Up @@ -58,10 +56,6 @@
TurnConfig,
TurnDelayConfig,
)
from aiperf.common.config.dev_config import (
DeveloperConfig,
print_developer_mode_warning,
)
from aiperf.common.config.endpoint_config import (
EndpointConfig,
)
Expand Down Expand Up @@ -128,9 +122,6 @@
"CLIParameter",
"ConversationConfig",
"ConversationDefaults",
"DevDefaults",
"DeveloperConfig",
"DeveloperOnlyCLI",
"DisableCLI",
"EndpointConfig",
"EndpointDefaults",
Expand Down Expand Up @@ -180,6 +171,5 @@
"parse_str_or_dict_as_tuple_list",
"parse_str_or_list",
"parse_str_or_list_of_positive_values",
"print_developer_mode_warning",
"print_str_or_list",
]
13 changes: 0 additions & 13 deletions src/aiperf/common/config/cli_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

from cyclopts import Parameter

from aiperf.common.config.groups import Groups
from aiperf.common.constants import AIPERF_DEV_MODE


class CLIParameter(Parameter):
"""Configuration for a CLI parameter.
Expand All @@ -27,13 +24,3 @@ class DisableCLI(CLIParameter):

def __init__(self, reason: str = "Not supported via command line", *args, **kwargs):
super().__init__(*args, parse=False, **kwargs)


class DeveloperOnlyCLI(CLIParameter):
"""Configuration for a CLI parameter that is only available to developers.

This is a subclass of the CLIParameter class that is used to set a CLI parameter to only be available to developers.
"""

def __init__(self, *args, **kwargs):
super().__init__(*args, parse=AIPERF_DEV_MODE, group=Groups.DEVELOPER, **kwargs)
17 changes: 0 additions & 17 deletions src/aiperf/common/config/config_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from dataclasses import dataclass
from pathlib import Path

from aiperf.common.constants import AIPERF_DEV_MODE
from aiperf.common.enums import (
AIPerfLogLevel,
AIPerfUIType,
Expand Down Expand Up @@ -185,19 +184,3 @@ class LoadGeneratorDefaults:
class WorkersDefaults:
MIN = None
MAX = None


@dataclass(frozen=True)
class DevDefaults:
if AIPERF_DEV_MODE:
ENABLE_YAPPI = False
DEBUG_SERVICES = None
TRACE_SERVICES = None
SHOW_INTERNAL_METRICS = True
DISABLE_UVLOOP = False
else:
ENABLE_YAPPI = False
DEBUG_SERVICES = None
TRACE_SERVICES = None
SHOW_INTERNAL_METRICS = False
DISABLE_UVLOOP = False
2 changes: 1 addition & 1 deletion src/aiperf/common/config/config_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import orjson

from aiperf.common.enums import ServiceType
from aiperf.common.enums.service_enums import ServiceType
from aiperf.common.utils import load_json_str

"""
Expand Down
104 changes: 0 additions & 104 deletions src/aiperf/common/config/dev_config.py

This file was deleted.

15 changes: 2 additions & 13 deletions src/aiperf/common/config/service_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
from typing import Annotated

from pydantic import Field, model_validator
from pydantic_settings import BaseSettings, SettingsConfigDict
from typing_extensions import Self

from aiperf.common.aiperf_logger import AIPerfLogger
from aiperf.common.config.base_config import ADD_TO_TEMPLATE
from aiperf.common.config.base_config import ADD_TO_TEMPLATE, BaseConfig
from aiperf.common.config.cli_parameter import CLIParameter, DisableCLI
from aiperf.common.config.config_defaults import ServiceDefaults
from aiperf.common.config.dev_config import DeveloperConfig
from aiperf.common.config.groups import Groups
from aiperf.common.config.worker_config import WorkersConfig
from aiperf.common.config.zmq_config import (
Expand All @@ -27,16 +25,9 @@
_logger = AIPerfLogger(__name__)


class ServiceConfig(BaseSettings):
class ServiceConfig(BaseConfig):
"""Base configuration for all services. It will be provided to all services during their __init__ function."""

model_config = SettingsConfigDict(
env_prefix="AIPERF_",
env_file=".env",
env_file_encoding="utf-8",
extra="allow",
)

_CLI_GROUP = Groups.SERVICE
_comm_config: BaseZMQCommunicationConfig | None = None

Expand Down Expand Up @@ -159,8 +150,6 @@ def validate_comm_config(self) -> Self:
),
] = ServiceDefaults.UI_TYPE

developer: DeveloperConfig = DeveloperConfig()

@property
def comm_config(self) -> BaseZMQCommunicationConfig:
"""Get the communication configuration."""
Expand Down
4 changes: 2 additions & 2 deletions src/aiperf/common/config/worker_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from aiperf.common.config.cli_parameter import CLIParameter, DisableCLI
from aiperf.common.config.config_defaults import WorkersDefaults
from aiperf.common.config.groups import Groups
from aiperf.common.constants import DEFAULT_MAX_WORKERS_CAP
from aiperf.common.environment import Environment


class WorkersConfig(BaseConfig):
Expand All @@ -29,7 +29,7 @@ class WorkersConfig(BaseConfig):
Field(
description="Maximum number of workers to create. If not specified, the number of"
" workers will be determined by the formula `min(concurrency, (num CPUs * 0.75) - 1)`, "
f" with a default max cap of `{DEFAULT_MAX_WORKERS_CAP}`. Any value provided will still be capped by"
f" with a default max cap of `{Environment.WORKER.MAX_WORKERS_CAP}`. Any value provided will still be capped by"
f" the concurrency value (if specified), but not by the max cap.",
),
CLIParameter(
Expand Down
Loading