Skip to content

Commit 64c8bcc

Browse files
authored
Merge pull request #24 from CogStack/doc-n-cli
fix: Remove potentially cached models and improve logging documentation
2 parents fd238cd + db0847a commit 64c8bcc

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,29 @@ docker compose -f docker-compose-mon.yml up -d
165165
#### Log management
166166
CMS provides a `log` stack to run services used for centralised logging and log analysis:
167167
```commandline
168-
export GRAYLOG_PASSWORD_SECRET=<GRAYLOG_PASSWORD_SECRET>
169-
export GRAYLOG_ROOT_PASSWORD_SHA2=<GRAYLOG_ROOT_PASSWORD_SHA2>
168+
export GRAYLOG_PASSWORD_SECRET=`openssl rand -hex 32`
169+
export GRAYLOG_ROOT_PASSWORD_SHA2=`echo -m "CHANGE_ME" | sha256`
170170
docker compose -f docker-compose-log.yml up -d
171171
```
172172

173+
After running this stack for the first time, you will need to create a default input to which CMS can send logs:
174+
175+
```commandline
176+
curl -u "admin:CHANGE_ME" \
177+
-X POST "http://localhost:9000/api/system/inputs" \
178+
-H "Content-Type: application/json" \
179+
-H "X-Requested-By: curl" \
180+
-d '{
181+
"title": "CMS GELF Input",
182+
"type": "org.graylog.plugins.gelf.inputs.GELFTCPInput",
183+
"global": true,
184+
"configuration": {
185+
"bind_address": "0.0.0.0",
186+
"port": 12201
187+
}
188+
}'
189+
```
190+
173191
#### Proxying
174192
A reverse proxying service is available inside the `proxy` stack:
175193
```commandline

app/cli/cli.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from huggingface_hub import snapshot_download # noqa
3636
from datasets import load_dataset # noqa
3737
from app import __version__ # noqa
38+
from app.config import Settings # noqa
3839
from app.domain import ModelType, TrainingType, BuildBackend, Device, ArchiveFormat, LlmEngine # noqa
3940
from app.registry import model_service_registry # noqa
4041
from app.api.api import (
@@ -44,7 +45,7 @@
4445
get_vllm_server,
4546
get_app_for_api_docs,
4647
) # noqa
47-
from app.utils import get_settings, send_gelf_message, download_model_package # noqa
48+
from app.utils import get_settings, send_gelf_message, download_model_package, get_model_data_package_base_name # noqa
4849
from app.management.model_manager import ModelManager # noqa
4950
from app.api.dependencies import ModelServiceDep, ModelManagerDep # noqa
5051
from app.management.tracker_client import TrackerClient # noqa
@@ -113,10 +114,7 @@ def serve_model(
113114
model_service_dep = ModelServiceDep(model_type, config, model_name)
114115
cms_globals.model_service_dep = model_service_dep
115116

116-
dst_model_path = os.path.join(parent_dir, "model", "model.zip" if model_path.endswith(".zip") else "model.tar.gz")
117-
config.BASE_MODEL_FILE = "model.zip" if model_path.endswith(".zip") else "model.tar.gz"
118-
if dst_model_path and os.path.exists(os.path.splitext(dst_model_path)[0]):
119-
shutil.rmtree(os.path.splitext(dst_model_path)[0])
117+
dst_model_path = _ensure_dst_model_path(model_path, parent_dir, config)
120118

121119
if model_path:
122120
if model_path.startswith("http://") or model_path.startswith("https://"):
@@ -221,15 +219,13 @@ def train_model(
221219
model_service_dep = ModelServiceDep(model_type, config)
222220
cms_globals.model_service_dep = model_service_dep
223221

224-
dst_model_path = os.path.join(parent_dir, "model", "model.zip" if base_model_path.endswith(".zip") else "model.tar.gz")
225-
config.BASE_MODEL_FILE = "model.zip" if base_model_path.endswith(".zip") else "model.tar.gz"
226-
if dst_model_path and os.path.exists(os.path.splitext(dst_model_path)[0]):
227-
shutil.rmtree(os.path.splitext(dst_model_path)[0])
222+
dst_model_path = _ensure_dst_model_path(base_model_path, parent_dir, config)
228223

229224
if base_model_path:
230225
try:
231226
shutil.copy2(base_model_path, dst_model_path)
232227
except shutil.SameFileError:
228+
logger.warning("Source and destination are the same model package file.")
233229
pass
234230
model_service = model_service_dep()
235231
model_service.model_name = model_name if model_name is not None else "CMS model"
@@ -708,6 +704,23 @@ def show_banner() -> None:
708704
typer.echo(banner)
709705

710706

707+
def _ensure_dst_model_path(model_path: str, parent_dir: str, config: Settings) -> str:
708+
if model_path.endswith(".zip"):
709+
dst_model_path = os.path.join(parent_dir, "model", "model.zip")
710+
config.BASE_MODEL_FILE = "model.zip"
711+
else:
712+
dst_model_path = os.path.join(parent_dir, "model", "model.tar.gz")
713+
config.BASE_MODEL_FILE = "model.tar.gz"
714+
model_dir = os.path.join(parent_dir, "model", "model")
715+
if os.path.exists(model_dir):
716+
shutil.rmtree(model_dir)
717+
if dst_model_path.endswith(".zip") and os.path.exists(dst_model_path.replace(".zip", ".tar.gz")):
718+
os.remove(dst_model_path.replace(".zip", ".tar.gz"))
719+
if dst_model_path.endswith(".tar.gz") and os.path.exists(dst_model_path.replace(".tar.gz", ".zip")):
720+
os.remove(dst_model_path.replace(".tar.gz", ".zip"))
721+
return dst_model_path
722+
723+
711724
def _get_logger(
712725
debug: Optional[bool] = None,
713726
model_type: Optional[ModelType] = None,

0 commit comments

Comments
 (0)