Skip to content

Commit

Permalink
Config: Add option to set priority to realtime
Browse files Browse the repository at this point in the history
Realtime process priority assigns resources to point to tabby's
processes. Running as administrator will give realtime priority
while running as a normal user will set as high priority.

Signed-off-by: kingbri <[email protected]>
  • Loading branch information
bdashore3 committed Jul 25, 2024
1 parent 5c082b7 commit 42bc4ad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
5 changes: 5 additions & 0 deletions config_sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ developer:
# NOTE: It's recommended to enable this, but if something breaks, turn this off.
#uvloop: False

# Set process to use a higher priority
# For realtime process priority, run as administrator or sudo
# Otherwise, the priority will be set to high
#realtime_process_priority: False

# Options for model overrides and loading
# Please read the comments to understand how arguments are handled between initial and API loads
model:
Expand Down
15 changes: 15 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from loguru import logger
from typing import Optional

import psutil

from common import config, gen_logging, sampling, model
from common.args import convert_args_to_dict, init_argparser
from common.auth import load_auth_keys
Expand Down Expand Up @@ -143,6 +145,19 @@ def entrypoint(arguments: Optional[dict] = None):

logger.warning("EXPERIMENTAL: Running program with Uvloop/Winloop.")

# Set the process priority
if unwrap(developer_config.get("realtime_process_priority"), False):
current_process = psutil.Process(os.getpid())
if platform.system() == "Windows":
current_process.nice(psutil.REALTIME_PRIORITY_CLASS)
else:
current_process.nice(psutil.IOPRIO_CLASS_RT)

logger.warning(
"EXPERIMENTAL: Process priority set to Realtime. \n"
"If you're not running on administrator/sudo, the priority is set to high."
)

# Enter into the async event loop
asyncio.run(entrypoint_async())

Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@ dependencies = [
"tokenizers",
"lm-format-enforcer >= 0.9.6",
"aiofiles",
"aiohttp",
"huggingface_hub",
"psutil",

# Improved asyncio loops
"uvloop ; platform_system == 'Linux' and platform_machine == 'x86_64'",
"winloop ; platform_system == 'Windows'",

# TEMP: Remove once 2.x is fixed in upstream
"numpy < 2.0.0",

# TODO: Maybe move these to a downloader feature?
"aiohttp",
"huggingface_hub",
]

[project.urls]
Expand Down

0 comments on commit 42bc4ad

Please sign in to comment.