code: def test_model_save_reload(tmpdir, hf_tokenizer):
      from transformers.models.roberta import (
          RobertaConfig,
          RobertaForSequenceClassification,
      )
  
      config = RobertaConfig(vocab_size=hf_tokenizer.vocab_size)
      model = RobertaForSequenceClassification(config)
      hf_model = HuggingFaceModel(
          model=model,
          tokenizer=hf_tokenizer,
          task="classification",
          model_dir=tmpdir,
          device=torch.device("cpu"),
      )
      hf_model._ensure_built()
      hf_model.save_checkpoint()
  
      model = RobertaForSequenceClassification(config)
      hf_model2 = HuggingFaceModel(
          model=model,
          tokenizer=hf_tokenizer,
          task="classification",
          model_dir=tmpdir,
          device=torch.device("cpu"),
      )
      hf_model2.restore()
  
      old_state = hf_model.model.state_dict()
      new_state = hf_model2.model.state_dict()
      matches = [
          torch.allclose(old_state[key], new_state[key])
          for key in old_state.keys()
      ]
  
      # all keys should match
      assert all(matches)
  
file_path: deepchem/deepchem/models/torch_models/tests/test_hf_models.py
imports: import os
  import deepchem
  import numpy
  import pytest
label_desc: Use image node_id 6 for calling a global function with example usage: test_model_save_reload(tmpdir, hf_tokenizer) without return types