Skip to content

Commit

Permalink
Tree: Use safe loader for YAML
Browse files Browse the repository at this point in the history
Also don't create module-level parsers where they're not needed.

Signed-off-by: kingbri <[email protected]>
  • Loading branch information
kingbri1 committed Sep 18, 2024
1 parent 6c7542d commit 0379440
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
7 changes: 4 additions & 3 deletions backends/exllamav2/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
from common.transformers_utils import GenerationConfig, HuggingFaceConfig
from common.utils import coalesce, unwrap

yaml = YAML()


class ExllamaV2Container:
"""The model container class for ExLlamaV2 models."""
Expand Down Expand Up @@ -381,7 +379,10 @@ async def set_model_overrides(self, **kwargs):
override_config_path, "r", encoding="utf8"
) as override_config_file:
contents = await override_config_file.read()
override_args = unwrap(yaml.safe_load(contents), {})

# Create a temporary YAML parser
yaml = YAML(typ="safe")
override_args = unwrap(yaml.load(contents), {})

# Merge draft overrides beforehand
draft_override_args = unwrap(override_args.get("draft"), {})
Expand Down
5 changes: 3 additions & 2 deletions common/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

from common.utils import coalesce

yaml = YAML()


class AuthKeys(BaseModel):
"""
Expand Down Expand Up @@ -59,6 +57,9 @@ async def load_auth_keys(disable_from_config: bool):

return

# Create a temporary YAML parser
yaml = YAML(typ="safe")

try:
async with aiofiles.open("api_tokens.yml", "r", encoding="utf8") as auth_file:
contents = await auth_file.read()
Expand Down
7 changes: 4 additions & 3 deletions common/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

from common.utils import unwrap, prune_dict

yaml = YAML()


# Common class for sampler params
class BaseSamplerRequest(BaseModel):
Expand Down Expand Up @@ -418,7 +416,10 @@ async def overrides_from_file(preset_name: str):
overrides_container.selected_preset = preset_path.stem
async with aiofiles.open(preset_path, "r", encoding="utf8") as raw_preset:
contents = await raw_preset.read()
preset = yaml.safe_load(contents)

# Create a temporary YAML parser
yaml = YAML(typ="safe")
preset = yaml.load(contents)
overrides_from_dict(preset)

logger.info("Applied sampler overrides from file.")
Expand Down
2 changes: 1 addition & 1 deletion common/tabby_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from common.config_models import BaseConfigModel, TabbyConfigModel
from common.utils import merge_dicts, unwrap

yaml = YAML()
yaml = YAML(typ="safe")


class TabbyConfig(TabbyConfigModel):
Expand Down

0 comments on commit 0379440

Please sign in to comment.