Repository: bentoml/BentoML

Issue:
bug: BentoML Sklearn Example won't work on >= bentoml==1.0.20
### Describe the bug

Following steps from [example](https://github.com/bentoml/BentoML/tree/main/examples/sklearn/pipeline)
 
bentoml serve service.py:svc will produce 

2023-06-08T08:24:26+0000 [ERROR] [runner:20_news_group:1] Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/starlette/routing.py", line 671, in lifespan
    async with self.lifespan_context(app):
  File "/usr/local/lib/python3.10/dist-packages/starlette/routing.py", line 566, in __aenter__
    await self._router.startup()
  File "/usr/local/lib/python3.10/dist-packages/starlette/routing.py", line 650, in startup
    handler()
  File "/usr/local/lib/python3.10/dist-packages/bentoml/_internal/server/runner_app.py", line 74, in _init_metrics_wrappers
    self.legacy_adaptive_batch_size_hist_map = {
  File "/usr/local/lib/python3.10/dist-packages/bentoml/_internal/server/runner_app.py", line 75, in <dictcomp>
    method.name: metrics_client.Histogram(
  File "/usr/local/lib/python3.10/dist-packages/prometheus_client/metrics.py", line 558, in __init__
    super().__init__(
  File "/usr/local/lib/python3.10/dist-packages/prometheus_client/metrics.py", line 130, in __init__
    raise ValueError('Invalid metric name: ' + self._name)
ValueError: Invalid metric name: 20_news_group_1_predict_adaptive_batch_size

ValueError not appeared on pip3 install bentoml==1.0.19

### To reproduce

pip install bentoml==1.0.21
follow instructions from https://github.com/bentoml/BentoML/tree/main/examples/sklearn/pipeline

### Expected behavior

_No response_

### Environment

bentoml==1.0.20 or bentoml==1.0.21
Python 3.10.7
Ubuntu 22.10


Discussion:
Hi @khakimov !
Thank you very much for pointing out this issue. Renaming '20_news_group' to 'news_group_20' in both 'train.py' and 'service.py', re-saving the model will solve this problem. We will also fix this issue in the repository soon.

Resolving patch:
diff --git a/examples/sklearn/pipeline/service.py b/examples/sklearn/pipeline/service.py
--- a/examples/sklearn/pipeline/service.py
+++ b/examples/sklearn/pipeline/service.py
@@ -2,7 +2,7 @@
 from bentoml.io import JSON
 from bentoml.io import Text
 
-bento_model = bentoml.sklearn.get("20_news_group:latest")
+bento_model = bentoml.sklearn.get("twenty_news_group:latest")
 
 target_names = bento_model.custom_objects["target_names"]
 model_runner = bento_model.to_runner()
diff --git a/examples/sklearn/pipeline/train.py b/examples/sklearn/pipeline/train.py
--- a/examples/sklearn/pipeline/train.py
+++ b/examples/sklearn/pipeline/train.py
@@ -76,7 +76,7 @@
 print(f"Best parameters set: {best_parameters}")
 
 bento_model = bentoml.sklearn.save_model(
-    "20_news_group",
+    "twenty_news_group",
     grid_search.best_estimator_,
     signatures={
         "predict": {"batchable": True, "batch_dim": 0},
@@ -90,7 +90,7 @@
 print(f"Model saved: {bento_model}")
 
 # Test running inference with BentoML runner
-test_runner = bentoml.sklearn.get("20_news_group:latest").to_runner()
+test_runner = bentoml.sklearn.get("twenty_news_group:latest").to_runner()
 test_runner.init_local()
 assert test_runner.predict.run(["hello"]) == grid_search.best_estimator_.predict(
     ["hello"]


Test patch: