Repository: mlflow/mlflow

Issue:
[BUG] PyTorch LightningDeprecationWarning ModelSummary and get_gpu_memory_map
Thank you for submitting an issue. Please refer to our [issue policy](https://www.github.com/mlflow/mlflow/blob/master/ISSUE_POLICY.md) for additional information about bug reports. For help with debugging your code, please refer to [Stack Overflow](https://stackoverflow.com/questions/tagged/mlflow).

### Willingness to contribute
The MLflow Community encourages bug fix contributions. Would you or another member of your organization be willing to contribute a fix for this bug to the MLflow code base?

- [x] Yes. I can contribute a fix for this bug independently.
- [ ] Yes. I would be willing to contribute a fix for this bug with guidance from the MLflow community.
- [ ] No. I cannot contribute a bug fix at this time.

### System information
- **Have I written custom code (as opposed to using a stock example script provided in MLflow)**: No
- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: 20.04
- **MLflow installed from (source or binary)**: binary
- **MLflow version (run ``mlflow --version``)**: 1.24.0
- **Python version**: 3.8.10
- **npm version, if running the dev UI**: -
- **Exact command to reproduce**: `mlflow.pytorch.autolog()`

### Describe the problem
Calling `mlflow.pytorch.autolog()` produces a warning regarding a deprecation, see logs:

### Code to reproduce issue
`mlflow.pytorch.autolog()`

### Other info / logs
```
2022/03/29 10:36:17 WARNING mlflow.utils.autologging_utils: MLflow autologging encountered a warning: "/usr/local/lib/python3.8/dist-package
s/pytorch_lightning-1.6.0.dev0-py3.8.egg/pytorch_lightning/core/memory.py:16: LightningDeprecationWarning: `pytorch_lightning.core.memory.ge
t_memory_profile` and `pytorch_lightning.core.memory.get_gpu_memory_map` have been moved to `pytorch_lightning.utilities.memory` since v1.5 
and will be removed in v1.7."

2022/03/29 10:36:17 WARNING mlflow.utils.autologging_utils: MLflow autologging encountered a warning: "/usr/local/lib/python3.8/dist-package
s/pytorch_lightning-1.6.0.dev0-py3.8.egg/pytorch_lightning/core/memory.py:25: LightningDeprecationWarning: `pytorch_lightning.core.memory.La
yerSummary` and `pytorch_lightning.core.memory.ModelSummary` have been moved to `pytorch_lightning.utilities.model_summary` since v1.5 and w
ill be removed in v1.7."
```


### What component(s), interfaces, languages, and integrations does this bug affect?
Components 
- [x] `area/artifacts`: Artifact stores and artifact logging
- [ ] `area/build`: Build and test infrastructure for MLflow
- [ ] `area/docs`: MLflow documentation pages
- [ ] `area/examples`: Example code
- [ ] `area/model-registry`: Model Registry service, APIs, and the fluent client calls for Model Registry
- [ ] `area/models`: MLmodel format, model serialization/deserialization, flavors
- [ ] `area/projects`: MLproject format, project running backends
- [ ] `area/scoring`: MLflow Model server, model deployment tools, Spark UDFs
- [ ] `area/server-infra`: MLflow Tracking server backend
- [ ] `area/tracking`: Tracking Service, tracking client APIs, autologging

Interface 
- [ ] `area/uiux`: Front-end, user experience, plotting, JavaScript, JavaScript dev server
- [ ] `area/docker`: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
- [ ] `area/sqlalchemy`: Use of SQLAlchemy in the Tracking Service or Model Registry
- [ ] `area/windows`: Windows support

Language 
- [ ] `language/r`: R APIs and clients
- [ ] `language/java`: Java APIs and clients
- [ ] `language/new`: Proposals for new client languages

Integrations
- [ ] `integrations/azure`: Azure and Azure ML integrations
- [ ] `integrations/sagemaker`: SageMaker integrations
- [ ] `integrations/databricks`: Databricks integrations



Discussion:

Resolving patch:
diff --git a/mlflow/pyfunc/scoring_server/__init__.py b/mlflow/pyfunc/scoring_server/__init__.py
--- a/mlflow/pyfunc/scoring_server/__init__.py
+++ b/mlflow/pyfunc/scoring_server/__init__.py
@@ -136,14 +136,19 @@ def parse_json_input(json_input, orient="split", schema: Schema = None):
         )
 
 
-def parse_csv_input(csv_input):
+def parse_csv_input(csv_input, schema: Schema = None):
     """
     :param csv_input: A CSV-formatted string representation of a Pandas DataFrame, or a stream
                       containing such a string representation.
+    :param schema: Optional schema specification to be used during parsing.
     """
 
     try:
-        return pd.read_csv(csv_input)
+        if schema is None:
+            return pd.read_csv(csv_input)
+        else:
+            dtypes = dict(zip(schema.input_names(), schema.pandas_types()))
+            return pd.read_csv(csv_input, dtype=dtypes)
     except Exception:
         _handle_serving_error(
             error_message=(
@@ -262,7 +267,7 @@ def transformation():  # pylint: disable=unused-variable
         if mime_type == CONTENT_TYPE_CSV and not content_format:
             data = flask.request.data.decode("utf-8")
             csv_input = StringIO(data)
-            data = parse_csv_input(csv_input=csv_input)
+            data = parse_csv_input(csv_input=csv_input, schema=input_schema)
         elif mime_type == CONTENT_TYPE_JSON and not content_format:
             json_str = flask.request.data.decode("utf-8")
             data = infer_and_parse_json_input(json_str, input_schema)


Test patch:
diff --git a/tests/pyfunc/test_scoring_server.py b/tests/pyfunc/test_scoring_server.py
--- a/tests/pyfunc/test_scoring_server.py
+++ b/tests/pyfunc/test_scoring_server.py
@@ -12,6 +12,11 @@
 import sklearn.datasets as datasets
 import sklearn.neighbors as knn
 
+try:
+    from StringIO import StringIO
+except ImportError:
+    from io import StringIO
+
 from mlflow.exceptions import MlflowException
 import mlflow.pyfunc.scoring_server as pyfunc_scoring_server
 import mlflow.sklearn
@@ -63,6 +68,21 @@ def pandas_df_with_all_types():
     return pdf
 
 
+@pytest.fixture
+def pandas_df_with_csv_types():
+    pdf = pd.DataFrame(
+        {
+            "boolean": [True, False, True],
+            "integer": np.array([1, 2, 3], np.int32),
+            "long": np.array([1, 2, 3], np.int64),
+            "float": np.array([math.pi, 2 * math.pi, 3 * math.pi], np.float32),
+            "double": [math.pi, 2 * math.pi, 3 * math.pi],
+        }
+    )
+    pdf["string"] = pd.Series(["a", "b", "c"], dtype=DataType.string.to_pandas())
+    return pdf
+
+
 @pytest.fixture(scope="module")
 def sklearn_model():
     iris = datasets.load_iris()
@@ -429,6 +449,14 @@ def test_split_oriented_json_to_df():
     assert set(str(dt) for dt in df.dtypes) == {"object", "float64", "int64"}
 
 
+def test_parse_with_schema_csv(pandas_df_with_csv_types):
+    schema = Schema([ColSpec(c, c) for c in pandas_df_with_csv_types.columns])
+    df = _shuffle_pdf(pandas_df_with_csv_types)
+    csv_str = df.to_csv(index=False)
+    df = pyfunc_scoring_server.parse_csv_input(StringIO(csv_str), schema=schema)
+    assert schema == infer_signature(df[schema.input_names()]).inputs
+
+
 def test_parse_with_schema(pandas_df_with_all_types):
     schema = Schema([ColSpec(c, c) for c in pandas_df_with_all_types.columns])
     df = _shuffle_pdf(pandas_df_with_all_types)