Skip to content

Conversation

s-gavrenkov
Copy link
Contributor

@s-gavrenkov s-gavrenkov commented Aug 20, 2025

Added support for running Flask from the command line. This is required for launching the Flask app using the Gunicorn server with Gevent.
To be integrated with the following PR:
https://github.com/datarobot/datarobot-custom-templates/pull/419

s-gavrenkov and others added 30 commits August 13, 2025 18:40
…eration to help prevent logic diverging (#1615)

* Fix Drum Inline Runner and streamline DRUM options generation

* Cleanup

* Refactor setup to new file

* Fix mocks

* Add unit tests

* Change tracer
Bumps [keras](https://github.com/keras-team/keras) from 3.10.0 to 3.11.0.
- [Release notes](https://github.com/keras-team/keras/releases)
- [Commits](keras-team/keras@v3.10.0...v3.11.0)

---
updated-dependencies:
- dependency-name: keras
  dependency-version: 3.11.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* [RAPTOR-14453] Regen requirements.txt to fix CVE-2025-8747

This regenerates the requirements.txt file from requirements.in, to pull in the
latest keras 3.11.2, upgrading from 3.10.0. Upgrading past 3.11.0 fixes
CVE-2025-8747.

* Reconcile dependencies, updated IDs, tags

---------

Co-authored-by: svc-harness-git2 <[email protected]>
… chat` kwargs (#1621)

* Update DRUM version

* Update CHANGELOG.md
…onment (#1627)

* Bump requirements in GenAI Agents environment

* Update

* Reconcile dependencies, updated IDs, tags

---------

Co-authored-by: svc-harness-git2 <[email protected]>
…for credential cache daemon (#1630)

* [CFX-3334] Update to latest drgithelper and properly set permissions for credential cache daemon

* Reconcile dependencies, updated IDs, tags

---------

Co-authored-by: svc-harness-git2 <[email protected]>
* [RAPTOR-13851] pytorch: rebuild requirements to pull in updates

This rebuilds requirements.txt to pull in updates for pytorch to resolve
CVE-2025-3730.

* Reconcile dependencies, updated IDs, tags

---------

Co-authored-by: svc-harness-git2 <[email protected]>
* addd timeouts

* fiz black

* fix tests

* fixed black

* add timeout

* fixed

* replaced with RuntimeParameters

* removed unused import

* replaced with static methods
* add watchdog

* 5 attempts

* watchdog_additional

* fixed version

* add env USE_NIM_WATCHDOG

* add env USE_NIM_WATCHDOG

* fixed lint

* fixed version

* rever docker changes

* add changes

* removed changelogs

* max_attempts = 3

* replaced with os.kill(pid, signal.SIGTERM)

* renamed

* fixed comments

* add NIM_WATCHDOG_REQUEST_TIMEOUT and NIM_WATCHDOG_MAX_ATTEMPTS

* add logs

* fix lint
# Conflicts:
#	custom_model_runner/datarobot_drum/drum/root_predictors/prediction_server.py
#	custom_model_runner/datarobot_drum/drum/runtime.py
#	public_dropin_environments/python311_genai_agents/env_info.json
@engprod-2
Copy link

engprod-2 bot commented Sep 1, 2025

The Needs Review labels were added based on the following file changes.

Team @datarobot/core-modeling (#predictive-ai) was assigned because of changes in files:

custom_model_runner/datarobot_drum/drum/drum.py
custom_model_runner/datarobot_drum/drum/main.py
custom_model_runner/datarobot_drum/drum/root_predictors/prediction_server.py
custom_model_runner/datarobot_drum/drum/runtime.py
custom_model_runner/datarobot_drum/drum/server.py

Team @datarobot/genai-systems (#genai-systems) was assigned because of changes in files:

custom_model_runner/datarobot_drum/drum/drum.py
custom_model_runner/datarobot_drum/drum/main.py
custom_model_runner/datarobot_drum/drum/root_predictors/prediction_server.py
custom_model_runner/datarobot_drum/drum/runtime.py
custom_model_runner/datarobot_drum/drum/server.py

If you think that there are some issues with ownership, please discuss with C&A domain at #sdtk slack channel and create PR to update DRCODEOWNERS\CODEOWNERS file.

@s-gavrenkov s-gavrenkov changed the title Gavrenkov/poc gunicorn [RAPTOR-14353] Run flask server using CLI (gunicorn with gevent) Sep 1, 2025
@s-gavrenkov s-gavrenkov changed the title [RAPTOR-14353] Run flask server using CLI (gunicorn with gevent) [RAPTOR-14353] Run flask server using CLI (gunicorn with gevent support) Sep 1, 2025
signal interruptions, and starts the CMRunner for executing user-defined models.

Args:
flask_app: Optional[Flask] Flask application instance, used when running using command line.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..., used when running using command line.

It's always a command line, when running locally or when running DRUM in as a sidecar container.
Is the plan to setup Flask App when running DRUM as a sidecar?

Copy link
Contributor Author

@s-gavrenkov s-gavrenkov Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the old logic remains. It was made to run drum using command gunicorn -c gunicorn.conf.py app:app

if [ "$SERVER_TYPE" == "gunicorn" ]; then
    echo "Starting gunicorn server..."
    exec gunicorn -c gunicorn.conf.py app:app
else
    echo "Starting werkzeug (dev Flask) server..."
    exec drum server --sidecar --gpu-predictor=nim --logging-level=info "$@"
fi

# when running application via the command line (e.g., gunicorn worker)
pass
else:
if RuntimeParameters.has("USE_NIM_WATCHDOG") and str(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check for has(<attribute>) is redundant as you can check for RuntimeParameters.get("USE_NIM_WATCHDOG", "no") with default False value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I see it was defined in the original version so not critical for applying in current PR, just a suggestion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user should explicitly set this value.

signal interruptions, and starts the CMRunner for executing user-defined models.

Args:
flask_app: Optional[Flask] Flask application instance, used when running using command line.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flast_app is not optional for DrumRuntime so it can't be optional for main()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if flast_app is None it is created app = create_flask_app() in def get_flask_app(api_blueprint):

https://github.com/datarobot/datarobot-user-models/pull/1633/files#diff-1d592639344a14e290f1bd489098ef8322773e22f75ab54e7cd5280177bbfd43R34-R39

if self.worker_ctx:
# Add cleanup when running via the command line (gunicorn worker)
self.worker_ctx.defer_cleanup(
lambda: stats_collector.disable(), desc="stats_collector.disable()"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably lets add short but genuine descriptions, than simply the method name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

Copy link
Contributor

@amarmudrankit amarmudrankit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM you can address this before merge #1633 (review)

Copy link

@mbromanowsky mbromanowsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for Predictive AI

@s-gavrenkov s-gavrenkov merged commit 62d1c92 into master Sep 4, 2025
49 checks passed
@svc-engprod-git1 svc-engprod-git1 deleted the gavrenkov/POC-gunicorn branch September 4, 2025 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants