Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: created module level doc string. #13053

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions .github/scripts/mr_generate_summary.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Collect the results of the various model test runs which are done as part of
# the model regression CI pipeline and dump them as a single file artifact.
# This artifact will the then be published at the end of the tests.
from collections import defaultdict
import json
"""Collect the results of the various model test runs which are done as part of
the model regression CI pipeline and dump them as a single file artifact.
This artifact will the then be published at the end of the tests."""
import os
from pathlib import Path
import json

from typing import Dict, List
from collections import defaultdict
from pathlib import Path


def combine_result(
Expand Down
31 changes: 13 additions & 18 deletions .github/scripts/mr_publish_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import datetime
import json
import os
import re
from typing import Any, Dict, List, Text, Tuple

from datadog_api_client.v1 import ApiClient, Configuration
Expand Down Expand Up @@ -94,27 +95,21 @@ def transform_to_seconds(duration: Text) -> float:
duration: Examples: '1m27s', '1m27.3s', '27s', '1h27s', '1h1m27s'

Raises:
Exception: If the input is not supported.
Exception: If the value are not matched.

Returns:
Duration converted in seconds.
"""
h_split = duration.split("h")
if len(h_split) == 1:
rest = h_split[0]
hours = 0
else:
hours = int(h_split[0])
rest = h_split[1]
m_split = rest.split("m")
if len(m_split) == 2:
minutes = int(m_split[0])
seconds = float(m_split[1].rstrip("s"))
elif len(m_split) == 1:
minutes = 0
seconds = float(m_split[0].rstrip("s"))
else:
raise Exception(f"Unsupported duration: {duration}")
time_pattern = r'(?:(?P<hours>\d+)h)?(?:(?P<minutes>\d+)m)?(?:(?P<seconds>\d+(?:\.\d+)?)s)?'
match = re.match(time_pattern, duration)

if not match:
raise ValueError(f"Invalid duration format: {duration}")

hours = float(match.group("hours") or 0)
minutes = float(match.group("minuts") or 0)
seconds = float(match.group("seconds") or 0)

overall_seconds = hours * 60 * 60 + minutes * 60 + seconds
return overall_seconds

Expand Down Expand Up @@ -277,7 +272,7 @@ def generate_json(file: Text, task: Text, data: dict) -> dict:

def create_report_file() -> None:
data = {}
for dirpath, dirnames, files in os.walk(os.environ["RESULT_DIR"]):
for dirpath, _, files in os.walk(os.environ["RESULT_DIR"]):
for f in files:
if f not in TASK_MAPPING.keys():
continue
Expand Down
39 changes: 10 additions & 29 deletions .github/tests/test_download_pretrained.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ def test_download_pretrained_lmf_exists_no_params():
assert lmf_specs[0].model_weights == "rasa/LaBSE"


def test_download_pretrained_lmf_exists_with_model_name():
def _common_step_cofig():
yaml = YAML(typ="safe")
config = yaml.load(CONFIG_FPATH)

steps = config.get("pipeline", [])
step = list( # noqa: RUF015
filter(lambda x: x["name"] == download_pretrained.COMP_NAME, steps)
)[0]
return step, steps, yaml, config


def test_download_pretrained_lmf_exists_with_model_name():
step, _, yaml, config = _common_step_cofig()
step["model_name"] = "roberta"
step["cache_dir"] = "/this/dir"

Expand All @@ -39,13 +44,7 @@ def test_download_pretrained_lmf_exists_with_model_name():


def test_download_pretrained_unknown_model_name():
yaml = YAML(typ="safe")
config = yaml.load(CONFIG_FPATH)

steps = config.get("pipeline", [])
step = list( # noqa: RUF015
filter(lambda x: x["name"] == download_pretrained.COMP_NAME, steps)
)[0]
step, _, yaml, config = _common_step_cofig()
step["model_name"] = "unknown"

with tempfile.NamedTemporaryFile("w+") as fp:
Expand All @@ -56,13 +55,7 @@ def test_download_pretrained_unknown_model_name():


def test_download_pretrained_multiple_model_names():
yaml = YAML(typ="safe")
config = yaml.load(CONFIG_FPATH)

steps = config.get("pipeline", [])
step = list( # noqa: RUF015
filter(lambda x: x["name"] == download_pretrained.COMP_NAME, steps)
)[0]
step, steps, yaml, config = _common_step_cofig()
step_new = deepcopy(step)
step_new["model_name"] = "roberta"
steps.append(step_new)
Expand All @@ -76,13 +69,7 @@ def test_download_pretrained_multiple_model_names():


def test_download_pretrained_with_model_name_and_nondefault_weight():
yaml = YAML(typ="safe")
config = yaml.load(CONFIG_FPATH)

steps = config.get("pipeline", [])
step = list( # noqa: RUF015
filter(lambda x: x["name"] == download_pretrained.COMP_NAME, steps)
)[0]
step, _, yaml, config = _common_step_cofig()
step["model_name"] = "bert"
step["model_weights"] = "bert-base-uncased"

Expand All @@ -95,13 +82,7 @@ def test_download_pretrained_with_model_name_and_nondefault_weight():


def test_download_pretrained_lmf_doesnt_exists():
yaml = YAML(typ="safe")
config = yaml.load(CONFIG_FPATH)

steps = config.get("pipeline", [])
step = list( # noqa: RUF015
filter(lambda x: x["name"] == download_pretrained.COMP_NAME, steps)
)[0]
step, steps, yaml, config = _common_step_cofig()
steps.remove(step)

with tempfile.NamedTemporaryFile("w+") as fp:
Expand Down