code: def test_optimize_model(Model, Tokenizer, model_path):
      with torch.inference_mode():
          tokenizer = Tokenizer.from_pretrained(
              model_path, trust_remote_code=True
          )
          input_ids = tokenizer.encode(prompt, return_tensors="pt").to(
              device
          )
  
          model = Model.from_pretrained(
              model_path,
              load_in_4bit=True,
              optimize_model=False,
              trust_remote_code=True,
          )
          model = model.to(device)
          logits_base_model = (model(input_ids)).logits
          model.to("cpu")  # deallocate gpu memory
  
          model = Model.from_pretrained(
              model_path,
              load_in_4bit=True,
              optimize_model=True,
              trust_remote_code=True,
          )
          model = model.to(device)
          logits_optimized_model = (model(input_ids)).logits
          model.to("cpu")
  
          assert all(
              torch.isclose(
                  logits_optimized_model, logits_base_model
              ).tolist()
          )
  
file_path: BigDL/python/llm/test/inference_gpu/test_transformers_api.py
imports: import os, time
  import pytest
  import torch
  from bigdl.llm.transformers import AutoModelForCausalLM, AutoModel, AutoModelForSpeechSeq2Seq
  from transformers import LlamaTokenizer, AutoTokenizer
label_desc: Use image node_id 3 for calling a global function with example usage: test_optimize_model(Model, Tokenizer, model_path) without return types