Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
combo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Syntactic Tools
combo
Commits
451eaad5
Commit
451eaad5
authored
Nov 20, 2023
by
Maja Jablonska
Browse files
Options
Downloads
Patches
Plain Diff
Workaround for different paths of archival models
parent
3c47dbf1
Branches
Branches containing commit
No related tags found
1 merge request
!46
Merge COMBO 3.0 into master
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
combo/modules/archival.py
+7
-2
7 additions, 2 deletions
combo/modules/archival.py
combo/modules/model.py
+20
-8
20 additions, 8 deletions
combo/modules/model.py
with
27 additions
and
10 deletions
combo/modules/archival.py
+
7
−
2
View file @
451eaad5
...
...
@@ -14,7 +14,7 @@ from combo.config import resolve
from
combo.data.dataset_loaders
import
DataLoader
from
combo.data.dataset_readers
import
DatasetReader
from
combo.modules.model
import
Model
from
combo.utils
import
ConfigurationError
CACHE_ROOT
=
Path
(
os
.
getenv
(
"
COMBO_CACHE_ROOT
"
,
Path
.
home
()
/
"
.combo
"
))
CACHE_DIRECTORY
=
str
(
CACHE_ROOT
/
"
cache
"
)
...
...
@@ -92,7 +92,12 @@ def load_archive(url_or_filename: Union[PathLike, str],
)
model
=
Model
.
load
(
archive_file
,
cuda_device
=
cuda_device
)
with
open
(
os
.
path
.
join
(
archive_file
,
'
config.json
'
),
'
r
'
)
as
f
:
config_path
=
os
.
path
.
join
(
archive_file
,
'
config.json
'
)
if
not
os
.
path
.
exists
(
config_path
):
config_path
=
os
.
path
.
join
(
archive_file
,
'
model/config.json
'
)
if
not
os
.
path
.
exists
(
config_path
):
raise
ConfigurationError
(
"
config.json is not stored in
"
+
str
(
archive_file
)
+
"
or
"
+
str
(
archive_file
)
+
"
/model
"
)
with
open
(
config_path
,
'
r
'
)
as
f
:
config
=
json
.
load
(
f
)
data_loader
,
validation_data_loader
,
dataset_reader
=
None
,
None
,
None
...
...
This diff is collapsed.
Click to expand it.
combo/modules/model.py
+
20
−
8
View file @
451eaad5
...
...
@@ -349,6 +349,10 @@ class Model(Module, pl.LightningModule, FromParameters):
# Load vocabulary from file
vocab_dir
=
os
.
path
.
join
(
serialization_dir
,
"
vocabulary
"
)
if
not
os
.
path
.
exists
(
vocab_dir
):
vocab_dir
=
os
.
path
.
join
(
serialization_dir
,
"
model/vocabulary
"
)
if
not
os
.
path
.
exists
(
vocab_dir
):
raise
ConfigurationError
(
"
Vocabulary not saved in
"
+
serialization_dir
+
"
or
"
+
serialization_dir
+
"
/model
"
)
# If the config specifies a vocabulary subclass, we need to use it.
vocab_params
=
config
.
get
(
"
vocabulary
"
)
if
vocab_params
[
'
type
'
]
==
'
from_files_vocabulary
'
:
...
...
@@ -403,12 +407,12 @@ class Model(Module, pl.LightningModule, FromParameters):
filter_out_authorized_missing_keys
(
model
)
#
if unexpected_keys or missing_keys:
#
raise RuntimeError(
#
f"Error loading state dict for {model.__class__.__name__}\n\t"
#
f"Missing keys: {missing_keys}\n\t"
#
f"Unexpected keys: {unexpected_keys}"
#
)
if
unexpected_keys
or
missing_keys
:
raise
RuntimeError
(
f
"
Error loading state dict for
{
model
.
__class__
.
__name__
}
\n\t
"
f
"
Missing keys:
{
missing_keys
}
\n\t
"
f
"
Unexpected keys:
{
unexpected_keys
}
"
)
return
model
...
...
@@ -447,13 +451,21 @@ class Model(Module, pl.LightningModule, FromParameters):
vocabulary and the trained weights.
"""
if
config
is
None
:
try
:
with
open
(
os
.
path
.
join
(
serialization_dir
,
'
config.json
'
),
'
r
'
)
as
f
:
config
=
json
.
load
(
f
)
except
FileNotFoundError
:
with
open
(
os
.
path
.
join
(
serialization_dir
,
'
model/config.json
'
),
'
r
'
)
as
f
:
config
=
json
.
load
(
f
)
elif
isinstance
(
config
,
str
)
or
isinstance
(
config
,
PathLike
):
with
open
(
config
,
'
r
'
)
as
f
:
config
=
json
.
load
(
f
)
weights_file
=
weights_file
or
os
.
path
.
join
(
serialization_dir
,
'
weights.th
'
)
if
not
os
.
path
.
exists
(
weights_file
):
weights_file
=
os
.
path
.
join
(
serialization_dir
,
'
model/weights.th
'
)
if
not
os
.
path
.
exists
(
weights_file
):
raise
ConfigurationError
(
"
weights.th not in
"
+
serialization_dir
+
"
or
"
+
serialization_dir
+
"
/model
"
)
# Peak at the class of the model.
model_type
=
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment