Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Workers
Base Worker
Commits
bdde8927
Commit
bdde8927
authored
1 year ago
by
Eva Bardou
Committed by
Yoann Schneider
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Rename `--model-dir` to `--extras-dir`
parent
5df83b6d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!419
Rename `--model-dir` to `--extras-dir`
Pipeline
#138171
passed
1 year ago
Stage: test
Stage: build
Stage: release
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_worker/worker/base.py
+26
-24
26 additions, 24 deletions
arkindex_worker/worker/base.py
tests/test_base_worker.py
+20
-20
20 additions, 20 deletions
tests/test_base_worker.py
with
46 additions
and
44 deletions
arkindex_worker/worker/base.py
+
26
−
24
View file @
bdde8927
...
...
@@ -46,9 +46,9 @@ def _is_500_error(exc: Exception) -> bool:
return
500
<=
exc
.
status_code
<
600
class
Model
NotFoundError
(
Exception
):
class
ExtrasDir
NotFoundError
(
Exception
):
"""
Exception raised when the path towards the
model
is invalid
Exception raised when the path towards the
extras directory
is invalid
"""
...
...
@@ -101,10 +101,12 @@ class BaseWorker(object):
action
=
"
store_true
"
,
default
=
False
,
)
# To load models locally
# To load models
, datasets, etc,
locally
self
.
parser
.
add_argument
(
"
--model-dir
"
,
help
=
(
"
The path to a local model
'
s directory (development only).
"
),
"
--extras-dir
"
,
help
=
(
"
The path to a local directory to store extra files like models, datasets, etc (development only).
"
),
type
=
Path
,
)
...
...
@@ -371,39 +373,39 @@ class BaseWorker(object):
# By default give raw secret payload
return
secret
def
find_
model
_directory
(
self
)
->
Path
:
def
find_
extras
_directory
(
self
)
->
Path
:
"""
Find the local path to the
model
. This supports two modes:
- the worker runs in ponos, the
model
is available at `/data/extra_files` (first try) or `/data/current`.
Find the local path to the
directory to store extra files
. This supports two modes:
- the worker runs in ponos, the
directory
is available at `/data/extra_files` (first try) or `/data/current`.
- the worker runs locally, the developer may specify it using either
- the `
model
_dir` configuration parameter
- the `--
model
-dir` CLI parameter
- the `
extras
_dir` configuration parameter
- the `--
extras
-dir` CLI parameter
:return: Path to the
model
on disk
:return: Path to the
directory for extra files
on disk
"""
if
self
.
task_id
:
# When running in production with ponos, the agent
# downloads the model and set it either in
# - `/data/extra_files`
# - the current task work dir
extra_dir
=
self
.
task_data_dir
/
"
extra_files
"
if
extra_dir
.
exists
():
return
extra_dir
extra
s
_dir
=
self
.
task_data_dir
/
"
extra_files
"
if
extra
s
_dir
.
exists
():
return
extra
s
_dir
return
self
.
work_dir
else
:
model
_dir
=
self
.
config
.
get
(
"
model
_dir
"
,
self
.
args
.
model
_dir
)
if
model
_dir
is
None
:
raise
Model
NotFoundError
(
"
No path to the
model
was provided.
"
"
Please provide
model
_dir either through configuration
"
extras
_dir
=
self
.
config
.
get
(
"
extras
_dir
"
,
self
.
args
.
extras
_dir
)
if
extras
_dir
is
None
:
raise
ExtrasDir
NotFoundError
(
"
No path to the
directory for extra files
was provided.
"
"
Please provide
extras
_dir either through configuration
"
"
or as CLI argument.
"
)
model
_dir
=
Path
(
model
_dir
)
if
not
model
_dir
.
exists
():
raise
Model
NotFoundError
(
f
"
The path
{
model
_dir
}
does not link to any directory
"
extras
_dir
=
Path
(
extras
_dir
)
if
not
extras
_dir
.
exists
():
raise
ExtrasDir
NotFoundError
(
f
"
The path
{
extras
_dir
}
does not link to any directory
"
)
return
model
_dir
return
extras
_dir
def
find_parents_file_paths
(
self
,
filename
:
Path
)
->
List
[
Path
]:
"""
...
...
This diff is collapsed.
Click to expand it.
tests/test_base_worker.py
+
20
−
20
View file @
bdde8927
...
...
@@ -11,7 +11,7 @@ import pytest
from
arkindex.mock
import
MockApiClient
from
arkindex_worker
import
logger
from
arkindex_worker.worker
import
BaseWorker
,
ElementsWorker
from
arkindex_worker.worker.base
import
Model
NotFoundError
from
arkindex_worker.worker.base
import
ExtrasDir
NotFoundError
from
tests.conftest
import
FIXTURES_DIR
...
...
@@ -602,55 +602,55 @@ def test_load_local_secret(monkeypatch, tmp_path):
assert
worker
.
api_client
.
history
[
0
].
operation
==
"
RetrieveSecret
"
def
test_find_
model
_directory_ponos_no_extra_files
(
monkeypatch
):
def
test_find_
extras
_directory_ponos_no_extra_files
(
monkeypatch
):
monkeypatch
.
setenv
(
"
PONOS_TASK
"
,
"
my_task
"
)
monkeypatch
.
setenv
(
"
PONOS_DATA
"
,
"
/data
"
)
worker
=
BaseWorker
()
assert
worker
.
find_
model
_directory
()
==
Path
(
"
/data/current
"
)
assert
worker
.
find_
extras
_directory
()
==
Path
(
"
/data/current
"
)
def
test_find_
model
_directory_ponos_with_extra_files
(
monkeypatch
):
def
test_find_
extras
_directory_ponos_with_extra_files
(
monkeypatch
):
monkeypatch
.
setenv
(
"
PONOS_TASK
"
,
"
my_task
"
)
monkeypatch
.
setenv
(
"
PONOS_DATA
"
,
"
/data
"
)
# Make the `extra_files` folder exist
monkeypatch
.
setattr
(
"
pathlib.Path.exists
"
,
lambda
x
:
True
)
worker
=
BaseWorker
()
assert
worker
.
find_
model
_directory
()
==
Path
(
"
/data/extra_files
"
)
assert
worker
.
find_
extras
_directory
()
==
Path
(
"
/data/extra_files
"
)
def
test_find_
model
_directory_from_cli
(
monkeypatch
):
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
worker
"
,
"
--
model
-dir
"
,
"
model
s
"
])
def
test_find_
extras
_directory_from_cli
(
monkeypatch
):
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
worker
"
,
"
--
extras
-dir
"
,
"
extra_file
s
"
])
monkeypatch
.
setattr
(
"
pathlib.Path.exists
"
,
lambda
x
:
True
)
worker
=
BaseWorker
()
worker
.
args
=
worker
.
parser
.
parse_args
()
worker
.
config
=
{}
assert
worker
.
find_
model
_directory
()
==
Path
(
"
model
s
"
)
assert
worker
.
find_
extras
_directory
()
==
Path
(
"
extra_file
s
"
)
def
test_find_
model
_directory_from_config
(
monkeypatch
):
def
test_find_
extras
_directory_from_config
(
monkeypatch
):
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
worker
"
])
monkeypatch
.
setattr
(
"
pathlib.Path.exists
"
,
lambda
x
:
True
)
worker
=
BaseWorker
()
worker
.
args
=
worker
.
parser
.
parse_args
()
worker
.
config
=
{
"
model
_dir
"
:
"
model
s
"
}
assert
worker
.
find_
model
_directory
()
==
Path
(
"
model
s
"
)
worker
.
config
=
{
"
extras
_dir
"
:
"
extra_file
s
"
}
assert
worker
.
find_
extras
_directory
()
==
Path
(
"
extra_file
s
"
)
@pytest.mark.parametrize
(
"
model
_path, exists, error
"
,
"
extras
_path, exists, error
"
,
(
[
None
,
True
,
"
No path to the
model
was provided. Please provide
model
_dir either through configuration or as CLI argument.
"
,
"
No path to the
directory for extra files
was provided. Please provide
extras
_dir either through configuration or as CLI argument.
"
,
],
[
"
model
s
"
,
False
,
"
The path
model
s does not link to any directory
"
],
[
"
extra_file
s
"
,
False
,
"
The path
extra_file
s does not link to any directory
"
],
),
)
def
test_find_
model
_directory_not_found
(
monkeypatch
,
model
_path
,
exists
,
error
):
if
model
_path
:
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
worker
"
,
"
--
model
-dir
"
,
model
_path
])
def
test_find_
extras
_directory_not_found
(
monkeypatch
,
extras
_path
,
exists
,
error
):
if
extras
_path
:
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
worker
"
,
"
--
extras
-dir
"
,
extras
_path
])
else
:
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
worker
"
])
...
...
@@ -658,10 +658,10 @@ def test_find_model_directory_not_found(monkeypatch, model_path, exists, error):
worker
=
BaseWorker
()
worker
.
args
=
worker
.
parser
.
parse_args
()
worker
.
config
=
{
"
model
_dir
"
:
model
_path
}
worker
.
config
=
{
"
extras
_dir
"
:
extras
_path
}
with
pytest
.
raises
(
Model
NotFoundError
,
match
=
error
):
worker
.
find_
model
_directory
()
with
pytest
.
raises
(
ExtrasDir
NotFoundError
,
match
=
error
):
worker
.
find_
extras
_directory
()
def
test_find_parents_file_paths
(
responses
,
mock_base_worker_with_cache
,
tmp_path
):
...
...
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