Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

fix(revisions): find the reviewed pin whatever case the repo id is spelled in

Aashish902e328db519
diff --git a/laya/revisions.py b/laya/revisions.py
index c2bc19a8..85a31f3d 100644
--- a/laya/revisions.py
+++ b/laya/revisions.py
@@ -35,13 +35,33 @@ PINNED_REVISIONS: Dict[str, str] = {
REVIEWED = "reviewed"
+def _reviewed_pin(model_id_or_path: str) -> Optional[str]:
+ """The reviewed SHA for `model_id_or_path`, matching repo ids case-insensitively.
+
+ Hugging Face repo ids are case-insensitive -- ``ConvaiInnovations/Laya`` resolves to the
+ same repository as ``convaiinnovations/laya`` -- so a load that spells a released
+ checkpoint differently must still find its pin. Refusing it instead would report a
+ missing reviewed SHA for a repository that has one, which is the opposite of what the
+ control exists for. The table's keys keep the canonical lowercase spelling.
+ """
+ pinned = PINNED_REVISIONS.get(model_id_or_path)
+ if pinned is not None:
+ return pinned
+ wanted = model_id_or_path.lower()
+ for repo, sha in PINNED_REVISIONS.items():
+ if repo.lower() == wanted:
+ return sha
+ return None
+
+
def resolve_revision(model_id_or_path: str, revision: Optional[str] = None) -> Optional[str]:
"""Pick the revision to download.
An explicit `revision` is returned unchanged. Otherwise ``LAYA_REVISION``, stripped; empty or
unset means "not asked for". The variable holds either a commit SHA/branch/tag, applied to
every checkpoint load the way `Router(revision=)` applies one, or the word ``reviewed``, which
- looks `model_id_or_path` up in `PINNED_REVISIONS`.
+ looks `model_id_or_path` up in `PINNED_REVISIONS` -- case-insensitively, the way the Hub
+ itself reads repo ids, so `laya.load("ConvaiInnovations/Laya")` finds its pin.
``reviewed`` for a repository the table has no entry for raises rather than loading it
unpinned: a pin that quietly resolves to nothing is the failure mode this control exists to
@@ -52,7 +72,7 @@ def resolve_revision(model_id_or_path: str, revision: Optional[str] = None) -> O
if not value:
return None
if value == REVIEWED:
- pinned = PINNED_REVISIONS.get(model_id_or_path)
+ pinned = _reviewed_pin(model_id_or_path)
if pinned is None:
raise ValueError(
"laya: LAYA_REVISION=reviewed, but %r has no reviewed SHA in "
diff --git a/tests/test_revision_pinning.py b/tests/test_revision_pinning.py
index ef8eafdc..be57b24a 100644
--- a/tests/test_revision_pinning.py
+++ b/tests/test_revision_pinning.py
@@ -69,6 +69,28 @@ class ResolveRevisionTests(unittest.TestCase):
self.assertIsNone(resolve_revision("acme/custom-model"))
self.assertIsNone(resolve_revision("acme/custom-model", ""))
+ def test_reviewed_finds_the_pin_whatever_case_the_repo_is_spelled_in(self):
+ """Hugging Face resolves repo ids case-insensitively, so the pin lookup must too.
+
+ `laya.load("ConvaiInnovations/Laya")` under `LAYA_REVISION=reviewed` is the same
+ repository as the table's lowercase key. An exact-match lookup called it unpinned and
+ refused the load -- reporting a missing reviewed SHA for one that exists, the
+ opposite of what this control is for.
+ """
+ repo = "convaiinnovations/laya"
+ sha = PINNED_REVISIONS[repo]
+ for spelling in (repo, repo.upper(), repo.title(), repo.capitalize()):
+ with patch.dict(os.environ, {"LAYA_REVISION": "reviewed"}):
+ self.assertEqual(resolve_revision(spelling), sha, spelling)
+ # the explicit-argument form reaches the same branch
+ self.assertEqual(resolve_revision(spelling, "reviewed"), sha, spelling)
+
+ def test_reviewed_still_refuses_a_repo_the_table_does_not_have(self):
+ for spelling in ("Acme/Some-Model", "ACME/SOME-MODEL"):
+ with patch.dict(os.environ, {"LAYA_REVISION": "reviewed"}):
+ with self.assertRaises(ValueError, msg=spelling):
+ resolve_revision(spelling)
+
class SnapshotRevisionTests(unittest.TestCase):
def test_snapshot_layout(self):