Paul Hager commited on
Commit
17b30d7
·
1 Parent(s): 9e7da42

Added missing function that was deleted

Browse files
Files changed (1) hide show
  1. src/leaderboard/read_evals.py +30 -1
src/leaderboard/read_evals.py CHANGED
@@ -9,7 +9,36 @@ import numpy as np
9
 
10
  from src.display.formatting import make_clickable_model
11
  from src.display.utils import AutoEvalColumn, ModelType, Tasks, Precision, WeightType
12
- from src.submission.check_validity import is_model_on_hub
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
 
15
  @dataclass
 
9
 
10
  from src.display.formatting import make_clickable_model
11
  from src.display.utils import AutoEvalColumn, ModelType, Tasks, Precision, WeightType
12
+
13
+ from transformers import AutoConfig
14
+ from transformers.models.auto.tokenization_auto import AutoTokenizer
15
+
16
+ def is_model_on_hub(model_name: str, revision: str, token: str = None, trust_remote_code=False, test_tokenizer=False) -> tuple[bool, str]:
17
+ """Checks if the model model_name is on the hub, and whether it (and its tokenizer) can be loaded with AutoClasses."""
18
+ try:
19
+ config = AutoConfig.from_pretrained(model_name, revision=revision, trust_remote_code=trust_remote_code, token=token)
20
+ if test_tokenizer:
21
+ try:
22
+ tk = AutoTokenizer.from_pretrained(model_name, revision=revision, trust_remote_code=trust_remote_code, token=token)
23
+ except ValueError as e:
24
+ return (
25
+ False,
26
+ f"uses a tokenizer which is not in a transformers release: {e}",
27
+ None
28
+ )
29
+ except Exception as e:
30
+ return (False, "'s tokenizer cannot be loaded. Is your tokenizer class in a stable transformers release, and correctly configured?", None)
31
+ return True, None, config
32
+
33
+ except ValueError:
34
+ return (
35
+ False,
36
+ "needs to be launched with `trust_remote_code=True`. For safety reason, we do not allow these models to be automatically submitted to the leaderboard.",
37
+ None
38
+ )
39
+
40
+ except Exception as e:
41
+ return False, "was not found on hub!", None
42
 
43
 
44
  @dataclass