Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
amrBatch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
Service Desk
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
Tetras MARS
amrBatch
Commits
2224211a
Commit
2224211a
authored
2 years ago
by
David Rouquet
Browse files
Options
Downloads
Patches
Plain Diff
Multiprocessing run with initializer
parent
af8a5cee
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
amrbatch/main.py
+17
-8
17 additions, 8 deletions
amrbatch/main.py
with
17 additions
and
8 deletions
amrbatch/main.py
+
17
−
8
View file @
2224211a
...
...
@@ -16,6 +16,7 @@ import traceback
import
logging
import
multiprocessing_logging
import
multiprocessing
from
multiprocessing
import
Manager
from
amrlib.graph_processing.amr_plot
import
AMRPlot
from
filepath_manager
import
FilepathManager
...
...
@@ -89,21 +90,26 @@ def __generate_sentence_file(filepath_manager, workdata_list):
first
=
False
#==============================================================================
# Sentence Conversion to AMR
#==============================================================================
# Function executed when a worker is created in the pool
def
init_pool_worker
():
# declare scope of a new global variable
global
stog
amr_model_path
=
"
/home/daxid/hdd_data/jupyterlab_root/lib/amrModel/model_parse_xfm_bart_large-v0_1_0
"
# store argument in the global variable for this process
logger
.
info
(
"
-- Loading AMR model
"
)
stog
=
amrlib
.
load_stog_model
(
model_dir
=
amr_model_path
)
def
__run_conversion
(
arg_dict
):
data
=
arg_dict
[
'
data
'
]
amr_model_path
=
arg_dict
[
'
amr_model_path
'
]
logger
.
info
(
"
-- Loading AMR model
"
)
stog
=
amrlib
.
load_stog_model
(
model_dir
=
amr_model_path
)
#
logger.info("-- Loading AMR model")
#
stog = amrlib.load_stog_model(model_dir=amr_model_path)
logger
.
info
(
"
-- Converting sentences to AMR graphs
"
)
stog_result
=
stog
.
parse_sents
([
data
.
sentence
])
...
...
@@ -117,13 +123,16 @@ def __run_conversion(arg_dict):
def
__convert_sentences_to_graphs
(
amr_model_path
,
input_data_list
):
"""
Converting text sentences to AMR graphs
"""
global
stog
mapIterable
=
[]
for
data
in
input_data_list
:
arg_dict
=
{
'
data
'
:
data
,
'
amr_model_path
'
:
amr_model_path
}
mapIterable
=
mapIterable
+
[
arg_dict
]
number_of_processes
=
min
(
round
((
multiprocessing
.
cpu_count
()
-
1
)
/
4
),
len
(
input_data_list
))
with
multiprocessing
.
Pool
(
number_of_processes
)
as
p
:
#with multiprocessing.Pool(number_of_processes) as p:
with
multiprocessing
.
Pool
(
number_of_processes
,
initializer
=
init_pool_worker
)
as
p
:
result_data_list
=
p
.
map
(
__run_conversion
,
mapIterable
)
# result_data_list = []
...
...
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