Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
lm-evaluation-harness
Commits
60f52803
Commit
60f52803
authored
Jan 25, 2024
by
lintangsutawika
Browse files
revert back to use load_yaml_config but with modes
parent
6282a1be
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
27 deletions
+27
-27
lm_eval/tasks/__init__.py
lm_eval/tasks/__init__.py
+2
-2
lm_eval/utils.py
lm_eval/utils.py
+25
-25
No files found.
lm_eval/tasks/__init__.py
View file @
60f52803
...
...
@@ -96,7 +96,7 @@ class TaskManager(abc.ABC):
def
_get_config
(
self
,
name
):
assert
name
in
self
.
ALL_TASKS
yaml_path
=
self
.
_get_yaml_path
(
name
)
return
utils
.
load_yaml_config
(
yaml_path
)
return
utils
.
load_yaml_config
(
"full"
,
yaml_path
)
def
_get_tasklist
(
self
,
name
):
assert
self
.
_name_is_task
(
name
)
==
False
...
...
@@ -196,7 +196,7 @@ class TaskManager(abc.ABC):
for
f
in
file_list
:
if
f
.
endswith
(
".yaml"
):
yaml_path
=
os
.
path
.
join
(
root
,
f
)
config
=
utils
.
simple_
load_yaml_config
(
yaml_path
)
config
=
utils
.
load_yaml_config
(
"simple"
,
yaml_path
)
if
set
(
config
.
keys
())
==
set
(
PYTHON_TASK_KEYS
):
# This is a python class config
tasks_and_groups
[
config
[
"task"
]]
=
{
...
...
lm_eval/utils.py
View file @
60f52803
...
...
@@ -472,37 +472,37 @@ def get_git_commit_hash():
return
git_hash
def
simple_load_yaml_config
(
yaml_path
=
None
,
yaml_config
=
None
,
yaml_dir
=
None
):
def
ignore_constructor
(
loader
,
node
):
return
node
yaml
.
add_constructor
(
"!function"
,
ignore_constructor
)
with
open
(
yaml_path
,
"rb"
)
as
file
:
yaml_config
=
yaml
.
full_load
(
file
)
return
yaml_config
def
ignore_constructor
(
loader
,
node
):
return
node
def
import_function
(
loader
,
node
):
function_name
=
loader
.
construct_scalar
(
node
)
yaml_path
=
os
.
path
.
dirname
(
loader
.
name
)
*
module_name
,
function_name
=
function_name
.
split
(
"."
)
if
isinstance
(
module_name
,
list
):
module_name
=
"."
.
join
(
module_name
)
module_path
=
os
.
path
.
normpath
(
os
.
path
.
join
(
yaml_path
,
"{}.py"
.
format
(
module_name
))
)
spec
=
importlib
.
util
.
spec_from_file_location
(
module_name
,
module_path
)
module
=
importlib
.
util
.
module_from_spec
(
spec
)
spec
.
loader
.
exec_module
(
module
)
def
load_yaml_config
(
yaml_path
=
None
,
yaml_config
=
None
,
yaml_dir
=
None
):
def
import_function
(
loader
,
node
):
function_name
=
loader
.
construct_scalar
(
node
)
yaml_path
=
os
.
path
.
dirname
(
loader
.
name
)
function
=
getattr
(
module
,
function_name
)
return
function
*
module_name
,
function_name
=
function_name
.
split
(
"."
)
if
isinstance
(
module_name
,
list
):
module_name
=
"."
.
join
(
module_name
)
module_path
=
os
.
path
.
normpath
(
os
.
path
.
join
(
yaml_path
,
"{}.py"
.
format
(
module_name
))
)
spec
=
importlib
.
util
.
spec_from_file_location
(
module_name
,
module_path
)
module
=
importlib
.
util
.
module_from_spec
(
spec
)
spec
.
loader
.
exec_module
(
module
)
def
load_yaml_config
(
mode
=
"simple"
,
yaml_path
=
None
,
yaml_config
=
None
,
yaml_dir
=
None
):
function
=
getattr
(
module
,
function_name
)
return
function
if
mode
==
"simple"
:
constuctor_fn
=
ignore_constructor
elif
mode
==
"full"
:
constuctor_fn
=
import_function
# Add the import_function constructor to the YAML loader
yaml
.
add_constructor
(
"!function"
,
import_functio
n
)
yaml
.
add_constructor
(
"!function"
,
constuctor_f
n
)
if
yaml_config
is
None
:
with
open
(
yaml_path
,
"rb"
)
as
file
:
yaml_config
=
yaml
.
full_load
(
file
)
...
...
@@ -530,7 +530,7 @@ def load_yaml_config(yaml_path=None, yaml_config=None, yaml_dir=None):
path
=
os
.
path
.
join
(
yaml_dir
,
path
)
try
:
included_yaml_config
=
load_yaml_config
(
path
)
included_yaml_config
=
load_yaml_config
(
mode
=
mode
,
yaml_path
=
path
)
final_yaml_config
.
update
(
included_yaml_config
)
except
Exception
as
ex
:
# If failed to load, ignore
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment