Page MenuHomePhabricator

Fix revscoring model servers
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):
Revscoring models fail with the following logs.

Traceback (most recent call last):
  File "/srv/rev/revscoring_model/model.py", line 8, in <module>
    from revscoring_model.model_servers import (
  File "/srv/rev/revscoring_model/model_servers/__init__.py", line 1, in <module>
    from .model_server_mp import RevscoringModelMP
  File "/srv/rev/revscoring_model/model_servers/model_server_mp.py", line 8, in <module>
    from model_servers import RevscoringModel, RevscoringModelType
  File "/srv/rev/revscoring_model/model_servers/__init__.py", line 1, in <module>
    from .model_server_mp import RevscoringModelMP
  File "/srv/rev/revscoring_model/model_servers/model_server_mp.py", line 8, in <module>
    from model_servers import RevscoringModel, RevscoringModelType
ImportError: cannot import name 'RevscoringModel' from partially initialized module 'model_servers' (most likely due to a circular import) (/srv/rev/revscoring_model/model_servers/__init__.py)

What happens?:
A circular import happens after reording imports in a previous patch that we formatted all imports using isort https://gerrit.wikimedia.org/r/c/machinelearning/liftwing/inference-services/+/981718

Event Timeline

Change #1021384 had a related patch set uploaded (by Ilias Sarantopoulos; author: Ilias Sarantopoulos):

[machinelearning/liftwing/inference-services@main] revscoring: fix circular import

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

This was caused by a change in the order of the imports. RevscoringModelMP depends on RevscoringModel and RevscoringModelType.
There are 2 solutions:

  • import RevscoringModel first like this
from .model_servers import RevscoringModel, RevscoringModelType
from .model_server_mp import RevscoringModelMP

Although this would solve the problem we may end up with a similar failure in the future. The order of imports shouldn't affect the smooth execution of our code.

  • Use a relative import inside model_servers_mp.py. This way the RevscoringModelMP has direct access to the other 2 classes and doesn't access the module from the public interface, thus removing the circular dependency.
from .model_servers import RevscoringModel, RevscoringModelType

I made a patch which has already been tested using the second solution.

Change #1021384 merged by jenkins-bot:

[machinelearning/liftwing/inference-services@main] revscoring: fix circular import

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

Change #1021420 had a related patch set uploaded (by Ilias Sarantopoulos; author: Ilias Sarantopoulos):

[operations/deployment-charts@master] ml-services: fix revscoring model servers

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

Change #1021420 merged by jenkins-bot:

[operations/deployment-charts@master] ml-services: fix revscoring model servers

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

isarantopoulos claimed this task.
isarantopoulos moved this task from Unsorted to Blocked on the Machine-Learning-Team board.
isarantopoulos moved this task from Blocked to 2023-2024 Q4 Done on the Machine-Learning-Team board.