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
e7231e84
Commit
e7231e84
authored
Jan 23, 2024
by
lintangsutawika
Browse files
moved import_function into the config loading file
parent
d352a549
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
21 deletions
+21
-21
lm_eval/utils.py
lm_eval/utils.py
+21
-21
No files found.
lm_eval/utils.py
View file @
e7231e84
...
@@ -472,14 +472,27 @@ def get_git_commit_hash():
...
@@ -472,14 +472,27 @@ def get_git_commit_hash():
return
git_hash
return
git_hash
def
import_function
(
loader
,
node
):
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
load_yaml_config
(
yaml_path
=
None
,
yaml_config
=
None
,
yaml_dir
=
None
):
def
import_function
(
loader
,
node
):
function_name
=
loader
.
construct_scalar
(
node
)
function_name
=
loader
.
construct_scalar
(
node
)
yaml_path
=
os
.
path
.
dirname
(
loader
.
name
)
yaml_path
=
os
.
path
.
dirname
(
loader
.
name
)
*
module_name
,
function_name
=
function_name
.
split
(
"."
)
*
module_name
,
function_name
=
function_name
.
split
(
"."
)
if
isinstance
(
module_name
,
list
):
if
isinstance
(
module_name
,
list
):
module_name
=
"."
.
join
(
module_name
)
module_name
=
"."
.
join
(
module_name
)
module_path
=
os
.
path
.
normpath
(
os
.
path
.
join
(
yaml_path
,
"{}.py"
.
format
(
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
)
spec
=
importlib
.
util
.
spec_from_file_location
(
module_name
,
module_path
)
module
=
importlib
.
util
.
module_from_spec
(
spec
)
module
=
importlib
.
util
.
module_from_spec
(
spec
)
...
@@ -488,19 +501,6 @@ def import_function(loader, node):
...
@@ -488,19 +501,6 @@ def import_function(loader, node):
function
=
getattr
(
module
,
function_name
)
function
=
getattr
(
module
,
function_name
)
return
function
return
function
def
ignore_constructor
(
loader
,
node
):
return
node
def
simple_load_yaml_config
(
yaml_path
=
None
,
yaml_config
=
None
,
yaml_dir
=
None
):
yaml
.
add_constructor
(
"!function"
,
ignore_constructor
)
with
open
(
yaml_path
,
"rb"
)
as
file
:
yaml_config
=
yaml
.
full_load
(
file
)
return
yaml_config
def
load_yaml_config
(
yaml_path
=
None
,
yaml_config
=
None
,
yaml_dir
=
None
):
# Add the import_function constructor to the YAML loader
# Add the import_function constructor to the YAML loader
yaml
.
add_constructor
(
"!function"
,
import_function
)
yaml
.
add_constructor
(
"!function"
,
import_function
)
if
yaml_config
is
None
:
if
yaml_config
is
None
:
...
...
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