code: def save_model(
      name: Tag | str,
      model: pl.LightningModule,
      *,
      signatures: ModelSignaturesType | None = None,
      labels: t.Dict[str, str] | None = None,
      custom_objects: t.Dict[str, t.Any] | None = None,
      external_modules: t.List[ModuleType] | None = None,
      metadata: t.Dict[str, t.Any] | None = None,
  ) -> bentoml.Model:
      """
      Save a model instance to BentoML modelstore.
  
      Args:
          name (:code:`str`):
              Name for given model instance. This should pass Python identifier check.
          model (`pl.LightningModule`):
              Instance of model to be saved
          labels (:code:`Dict[str, str]`, `optional`, default to :code:`None`):
              user-defined labels for managing models, e.g. team=nlp, stage=dev
          custom_objects (:code:`Dict[str, Any]]`, `optional`, default to :code:`None`):
              user-defined additional python objects to be saved alongside the model,
              e.g. a tokenizer instance, preprocessor function, model configuration json
          external_modules (:code:`List[ModuleType]`, `optional`, default to :code:`None`):
              user-defined additional python modules to be saved alongside the model or custom objects,
              e.g. a tokenizer module, preprocessor module, model configuration module
          metadata (:code:`Dict[str, Any]`, `optional`, default to :code:`None`):
              Custom metadata for given model.
          model_store (:mod:`~bentoml._internal.models.store.ModelStore`, default to :mod:`BentoMLContainer.model_store`):
              BentoML modelstore, provided by DI Container.
  
      Returns:
          :obj:`~bentoml.Tag`: A :obj:`tag` with a format `name:version` where `name` is the user-defined model's name, and a generated `version` by BentoML.
  
      Examples:
  
      .. code-block:: python
  
          import bentoml
          import torch
          import pytorch_lightning as pl
  
          class LitClassifier(pl.LightningModule):
  
              def __init__(self, hidden_dim: int = 128, learning_rate: float = 0.0001):
                  super().__init__()
                  self.save_hyperparameters()
  
                  self.l1 = torch.nn.Linear(28 * 28, self.hparams.hidden_dim)
                  self.l2 = torch.nn.Linear(self.hparams.hidden_dim, 10)
  
              def forward(self, x):
                  x = x.view(x.size(0), -1)
                  x = torch.relu(self.l1(x))
                  x = torch.relu(self.l2(x))
                  return x
  
              def training_step(self, batch, batch_idx):
                  x, y = batch
                  y_hat = self(x)
                  loss = F.cross_entropy(y_hat, y)
                  return loss
  
              def validation_step(self, batch, batch_idx):
                  x, y = batch
                  y_hat = self(x)
                  loss = F.cross_entropy(y_hat, y)
                  self.log("valid_loss", loss)
  
              def test_step(self, batch, batch_idx):
                  x, y = batch
                  y_hat = self(x)
                  loss = F.cross_entropy(y_hat, y)
                  self.log("test_loss", loss)
  
              def configure_optimizers(self):
                  return torch.optim.Adam(self.parameters(), lr=self.hparams.learning_rate)
  
          tag = bentoml.pytorch_lightning.save_model("lit_classifier", LitClassifier())
      """
      if not isinstance(model, pl.LightningModule):
          raise TypeError(
              f"'model' must be an instance of 'pl.LightningModule', got {type(model)} instead."
          )
  
      script_module = model.to_torchscript()
  
      assert not isinstance(
          script_module, dict
      ), "Saving a dict of pytorch_lightning Module into one BentoModel is not supported"
  
      return script_save_model(
          name,
          script_module,
          signatures=signatures,
          labels=labels,
          custom_objects=custom_objects,
          external_modules=external_modules,
          metadata=metadata,
          _framework_name="pytorch_lightning",
          _module_name=MODULE_NAME,
      )
  
file_path: BentoML/src/bentoml/_internal/frameworks/pytorch_lightning.py
imports: from __future__ import annotations
  import typing
  from types import ModuleType
  from typing import TYPE_CHECKING
  import bentoml
  from bentoml import Tag
  from ...exceptions import MissingDependencyException
  from ...exceptions import NotFound
  from ..models.model import Model
  from .common.pytorch import torch
  from .torchscript import MODEL_FILENAME
  from .torchscript import save_model
label_desc: Use image node_id 3 for calling a global function with example usage: save_model(name, model) and returns: script_save_model