メインコンテンツまでスキップ
バージョン: v2603

intelligence.zenith_tune.command

OptionFormat Objects

class OptionFormat(Enum)

Enum for different option formats.

EQUALS

Example: --key=value

SPACE

Example: --key value

KEYVALUE

Example: --env KEY1=value1 KEY2=value2

FLAG

Example: --verbose

Option Objects

@dataclass
class Option()

Represents a command-line option.

OptionHandler Objects

class OptionHandler(ABC)

Abstract base class for option handlers.

can_handle

@abstractmethod
def can_handle(option: Option) -> bool

Check if this handler can handle the given option.

append

@abstractmethod
def append(args: List[str],
option: Option,
keys_match: _KeysMatch = _exact_match,
delimiter: Optional[str] = " ") -> List[str]

Append an option to the argument list.

Arguments:

  • args - Current argument list.
  • option - Option to append.
  • keys_match - Key comparison function.
  • delimiter - Delimiter for joining values to an existing key. " " (default) joins with space, "," with comma, etc. None forces a new key (no deduplication).

update

@abstractmethod
def update(args: List[str],
option: Option,
keys_match: _KeysMatch = _exact_match) -> List[str]

Update an option in the argument list.

remove

@abstractmethod
def remove(args: List[str],
key: str,
keys_match: _KeysMatch = _exact_match) -> List[str]

Remove an option from the argument list.

CommandBuilder Objects

class CommandBuilder()

Improved command builder with better separation of concerns.

__init__

def __init__(command: str = "", *, normalize: bool = False)

Initialize CommandBuilder.

Arguments:

  • command - Command string to parse.
  • normalize - If True, treat hyphens and underscores as equivalent when matching option keys (e.g. --batch-size matches --batch_size).

update

def update(option: str) -> "CommandBuilder"

Update an option.

append

def append(option: str, delimiter: Optional[str] = " ") -> "CommandBuilder"

Append an option.

Arguments:

  • option - Option string to append.
  • delimiter - Delimiter for joining values to an existing key. " " (default) joins with space, "," with comma, etc. None forces a new key (no deduplication).

remove

def remove(option: str) -> "CommandBuilder"

Remove an option.

get_command

def get_command() -> str

Get the command string.

staging_directory

def staging_directory(old_path: str,
new_path: str,
copy_files: bool = False) -> "CommandBuilder"

Replace directory paths in command and optionally copy directory for distributed training.

Arguments:

  • old_path - Path to replace in the command
  • new_path - New path to use in the command
  • copy_files - Whether to actually copy the directory (default: False)

Returns:

CommandBuilder instance for method chaining

Raises:

  • FileNotFoundError - If old_path doesn't exist and copy_files is True
  • NotADirectoryError - If old_path is not a directory and copy_files is True
  • OSError - If copying fails

EqualsHandler Objects

class EqualsHandler(OptionHandler)

Handler for --key=value format.

SpaceHandler Objects

class SpaceHandler(OptionHandler)

Handler for --key value format.

FlagHandler Objects

class FlagHandler(OptionHandler)

Handler for --flag format.

KeyValueHandler Objects

class KeyValueHandler(OptionHandler)

Handler for --key key1=value1 key2=value2 format.