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

Add a variant field to the remote settings util #996

Merged
merged 1 commit into from
Feb 7, 2025
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
17 changes: 7 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pyperclip="1.9.0"
ruamel-yaml = "^0.18.6"
taskcluster = "^56.0.3"
taskcluster-taskgraph = "^11.1.0"
kinto-http="11.7.0"
kinto-http="11.7.1"
# Use an outdated version of pydantic due to dependency requirements conflict.
pydantic="1.10.19"

Expand Down
1 change: 1 addition & 0 deletions utils/common/remote_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class WasmResponse(BaseModel):
class ModelRecord(BaseModel):
name: str # "model.enel.intgemm.alphas.bin"
schema_name: Optional[int] = Field(default=None, alias="schema")
variant: Optional[str] = None
toLang: str # "en"
fromLang: str # "el"
version: str # "1.0"
Expand Down
32 changes: 4 additions & 28 deletions utils/local_remote_settings/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,6 @@
bucket = "main"


def make_valid_locale_code(lang_tag: str, experiment: str) -> str:
"""
Make a BCP 47 locale out of a language tag, and stuff the experiment name into the private
use subtags. This is a best effort to make a valid locale, and may still fail to generate
one that is parseable by ICU.

e.g.

make_valid_locale_code(lang_tag="en", experiment="my-experiment")
> "en-xmy-xexperi3"
"""
words = re.split(r"[^a-zA-Z0-9]", experiment)
private_use = ""
for word in words:
if re.match(r"^[0-9]+", word):
# Add numbers to the string without an "-x", as private use subtags
# like "-x3" don't appear to be valid.
private_use += word
else:
# The tags are limited in size, leave room for a single digit number.
private_use += f"-x{word[:6]}"

return f"{lang_tag}{private_use}"


def sync_records(
remote_settings: Client,
collection: str,
Expand Down Expand Up @@ -470,9 +445,10 @@ def add_model_from_export_task(
record = ModelRecord(
name=filename,
schema=0,
# Fake a locale out of the language tag and experiment name, e.g. "en-testDecoderSize"
fromLang=make_valid_locale_code(src, experiment_name),
toLang=make_valid_locale_code(trg, experiment_name),
fromLang=src,
toLang=trg,
# Include the experiment name as a variant.
variant=experiment_name,
version="1.0",
fileType=filename.split(".")[0], # lex, model, vocab
attachment=None,
Expand Down