Page MenuHomePhabricator

Investigate why the add-a-link training pipeline concludes with missing datasets
Closed, ResolvedPublic

Description

In T344799 integration tests for research/mwaddlink are failing because there are missing files in the simplewiki datasets.

Tried re-running the training pipeline for simplewiki and it generated the following datasets:

$ ls data/simplewiki/
lr_simplewiki_anchors.sql.gz           lr_simplewiki_redirects.sql.gz.checksum    simplewiki.redirects.sqlite  simplewiki.w2vfiltered.sqlite
lr_simplewiki_anchors.sql.gz.checksum  lr_simplewiki_w2vfiltered.sql.gz           simplewiki.w2v.bin           simplewiki.w2v_lg.pkl
lr_simplewiki_pageids.sql.gz           lr_simplewiki_w2vfiltered.sql.gz.checksum  simplewiki.w2v.db            simplewiki.w2v_mention.pkl
lr_simplewiki_pageids.sql.gz.checksum  simplewiki.anchors.sqlite                  simplewiki.w2v.db-lock       testing
lr_simplewiki_redirects.sql.gz         simplewiki.pageids.sqlite                  simplewiki.w2v_dic.pkl       training

Checked to confirm whether all datasets that should be published exist and noticed the following are missing:

simplewiki.pageids.sqlite.checksum
simplewiki.w2vfiltered.sqlite.gz
simplewiki.anchors.sqlite.checksum
simplewiki.pageids.sqlite.gz
lr_simplewiki_anchors.sql.gz
simplewiki.anchors.sqlite.gz
simplewiki.redirects.sqlite.checksum
simplewiki.linkmodel.json
simplewiki.redirects.sqlite.gz
lr_simplewiki_pageids.sql.gz
simplewiki.linkmodel.json.checksum
simplewiki.w2vfiltered.sqlite.checksum

Not yet sure why the training pipeline is not generating these files. Going to investigate this.

Details

Related Changes in Gerrit:

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Stepped through the execution of the training pipeline and discovered that generate_anchor_dictionary_spark.py does not generate the expected files. This is likely to be caused by a spark session that no longer connects even when kerberos credentials are enabled on stat1008.

Reproduced the spark session connection issue as shown below:

(link-recommendation-env) kevinbazira@stat1008:~/research-mwaddlink-v1/src/scripts$ python
Python 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:23:14) [GCC 10.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from wmfdata.spark import create_custom_session
>>> spark = create_custom_session(
...     master="yarn",
...     app_name="generating-anchors",
...     spark_config={
...         "spark.driver.memory": "2g",
...         "spark.dynamicAllocation.maxExecutors": 128,
...         "spark.executor.memory": "8g",
...         "spark.executor.cores": 4
...     }
... )
SPARK_HOME: /usr/lib/spark3
Using Hadoop client lib jars at 3.2.0, provided by Spark.
PYSPARK_PYTHON=/home/kevinbazira/.conda/envs/link-recommendation-env/bin/python3
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
23/08/24 00:50:23 WARN SparkConf: Note that spark.local.dir will be overridden by the value set by the cluster manager (via SPARK_LOCAL_DIRS in mesos/standalone/kubernetes and LOCAL_DIRS in YARN).
23/08/24 00:50:24 WARN Utils: Service 'sparkDriver' could not bind on port 12000. Attempting port 12001.
23/08/24 00:50:24 WARN Utils: Service 'sparkDriver' could not bind on port 12001. Attempting port 12002.
23/08/24 00:50:24 WARN Utils: Service 'SparkUI' could not bind on port 4040. Attempting port 4041.
23/08/24 00:50:24 WARN Utils: Service 'SparkUI' could not bind on port 4041. Attempting port 4042.
23/08/24 00:50:32 WARN Utils: Service 'org.apache.spark.network.netty.NettyBlockTransferService' could not bind on port 13000. Attempting port 13001.
23/08/24 00:50:32 WARN Utils: Service 'org.apache.spark.network.netty.NettyBlockTransferService' could not bind on port 13001. Attempting port 13002.
23/08/24 00:50:32 WARN YarnSchedulerBackend$YarnSchedulerEndpoint: Attempted to request executors before the AM has registered!

Reproduced the spark session connection issue as shown below:

...
23/08/24 00:50:23 WARN SparkConf: Note that spark.local.dir will be overridden by the value set by the cluster manager (via SPARK_LOCAL_DIRS in mesos/standalone/kubernetes and LOCAL_DIRS in YARN).
23/08/24 00:50:24 WARN Utils: Service 'sparkDriver' could not bind on port 12000. Attempting port 12001.
23/08/24 00:50:24 WARN Utils: Service 'sparkDriver' could not bind on port 12001. Attempting port 12002.
23/08/24 00:50:24 WARN Utils: Service 'SparkUI' could not bind on port 4040. Attempting port 4041.
23/08/24 00:50:24 WARN Utils: Service 'SparkUI' could not bind on port 4041. Attempting port 4042.
23/08/24 00:50:32 WARN Utils: Service 'org.apache.spark.network.netty.NettyBlockTransferService' could not bind on port 13000. Attempting port 13001.
23/08/24 00:50:32 WARN Utils: Service 'org.apache.spark.network.netty.NettyBlockTransferService' could not bind on port 13001. Attempting port 13002.
23/08/24 00:50:32 WARN YarnSchedulerBackend$YarnSchedulerEndpoint: Attempted to request executors before the AM has registered!

I don't actually see any error here. Those warning messages are annoying but normal (T315024). Is there something I'm missing?

@MGerlach and I looked into why the spark jobs in the training pipeline weren't running and discovered that they weren't able to run python even when it existed. The error below was being thrown:

(an-worker1092.eqiad.wmnet executor 1): java.io.IOException: Cannot run program "/home/kevinbazira/.conda/envs/adda-link-env/bin/python3": error=2, No such file or directory

We decided to pack the conda env and adapt the spark command to use the packed env (i.e --archives environment.tar.gz#environment). The adapted spark job was able to run successfully as shown below:

(link-recommendation-env) kevinbazira@stat1008:~/research-mwaddlink-v1/src/scripts$ conda pack -o environment.tar.gz
.
.
.
(link-recommendation-env) kevinbazira@stat1008:~/research-mwaddlink-v1/src/scripts$ PYSPARK_PYTHON=~/.conda/envs/adda-link-env/bin/python3.10 PYSPARK_DRIVER_PYTHON=~/.conda/envs/adda-link-env/bin/python3.10 spark3-submit --master yarn --executor-memory 8G --executor-cores 4 --driver-memory 2G --conf spark.dynamicAllocation.maxExecutors=128 --archives environment.tar.gz#environment generate_anchor_dictionary_spark.py $WIKI_ID
.
.
.
(link-recommendation-env) kevinbazira@stat1008:~/research-mwaddlink-v1/src/scripts$ ls ../../data/simplewiki
simplewiki.anchors.pkl  simplewiki.pageids.pkl  simplewiki.redirects.pkl  testing  training

The next step was to adapt the entire training pipeline (i.e run-pipeline.sh) to use a packed env and on running it, the error below was thrown:

$ WIKI_ID="simplewiki" ./run-pipeline.sh
.
.
.
RUNNING wikipedia2vec on dump
Traceback (most recent call last):
  File "/home/kevinbazira/.conda/envs/link-recommendation-env/bin/wikipedia2vec", line 5, in <module>
    from wikipedia2vec.cli import cli
  File "/home/kevinbazira/.conda/envs/link-recommendation-env/lib/python3.10/site-packages/wikipedia2vec/__init__.py", line 4, in <module>
    from .dictionary import Dictionary
  File "wikipedia2vec/dictionary.pyx", line 1, in init wikipedia2vec.dictionary
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

We noticed that wikipedia2vec only compatible up to python3.8 or lower (1, 2) yet the conda env uses python3.10

The resolution here is to use a conda env (python3.10) to run the spark jobs and a python3.7 env to run wikipedia2vec.

We adapted the training pipeline:

  1. spark jobs run within the conda env (python3.10)
  2. spark commands distribute conda env as an archive to the jobs
  3. python3.7 env is used to train wikipedia2vec and filter its output

Re-running the training pipeline for simplewiki generated all the expected datasets:

(venv) (link-recommendation-env) kevinbazira@stat1008:~/research-mwaddlink-v1$ ls data/simplewiki/
lr_simplewiki_anchors.sql.gz               simplewiki.anchors.sqlite.checksum  simplewiki.redirects.sqlite.checksum
lr_simplewiki_anchors.sql.gz.checksum      simplewiki.anchors.sqlite.gz        simplewiki.redirects.sqlite.gz
lr_simplewiki_pageids.sql.gz               simplewiki.linkmodel.json           simplewiki.w2vfiltered.pkl
lr_simplewiki_pageids.sql.gz.checksum      simplewiki.linkmodel.json.checksum  simplewiki.w2vfiltered.sqlite
lr_simplewiki_redirects.sql.gz             simplewiki.pageids.pkl              simplewiki.w2vfiltered.sqlite.checksum
lr_simplewiki_redirects.sql.gz.checksum    simplewiki.pageids.sqlite           simplewiki.w2vfiltered.sqlite.gz
lr_simplewiki_w2vfiltered.sql.gz           simplewiki.pageids.sqlite.checksum  simplewiki.wdproperties.pkl
lr_simplewiki_w2vfiltered.sql.gz.checksum  simplewiki.pageids.sqlite.gz        testing
simplewiki.anchors.pkl                     simplewiki.redirects.pkl            training
simplewiki.anchors.sqlite                  simplewiki.redirects.sqlite

We have published the simplewiki datasets to unblock T344799#9121093.

Going to push a patch that adds this fix to the training pipeline.

Change 952341 had a related patch set uploaded (by Kevin Bazira; author: Kevin Bazira):

[research/mwaddlink@main] Fix model training pipeline

https://gerrit.wikimedia.org/r/952341

Following T345091#9124589, we learned that the sqlitedict package was using pickle protocol 5 via HIGHEST_PROTOCOL within the python3.10 environment. To avoid running into the unsupported pickle protocol: 5 issue, we are going to run all scripts that rely on this package within the python3.7 environment.

Change 952341 merged by jenkins-bot:

[research/mwaddlink@main] Fix model training pipeline

https://gerrit.wikimedia.org/r/952341

The model training pipeline has been fixed and it now generates all the expected datasets that should be published. Below is a summary of what was fixed:

  1. use conda env (python3.10) to run spark jobs
  2. spark commands distribute conda env as an archive to the jobs
  3. use python3.7 env to:
    • train wikipedia2vec and filter its output
    • enable sqlitedict to use pickle protocol 4 instead of 5
  4. update README docs on setting up the 2 python envs mentioned above
  5. adapt requirements.txt dependency versions to support python3.7
  6. explicitly set protocol 4 in both generate_anchor_dictionary and generate_wdproperties_spark scripts that were still using pickle protocol 5 via HIGHEST_PROTOCOL.

Thanks a lot, @MGerlach for all your help on this!