code: def test_load_from_pretrained_embeddings(tmpdir):
      from deepchem.models.torch_models.grover import GroverModel
      from deepchem.feat.vocabulary_builders import (
          GroverAtomVocabularyBuilder,
          GroverBondVocabularyBuilder,
      )
  
      atom_vocabulary = GroverAtomVocabularyBuilder(max_size=100)
      bond_vocabulary = GroverBondVocabularyBuilder(max_size=100)
  
      pretrain_dir = os.path.join(tmpdir, "pretrain_model")
      model_config = {
          "node_fdim": 151,
          "edge_fdim": 165,
          "atom_vocab": atom_vocabulary,
          "bond_vocab": bond_vocabulary,
          "features_dim": 2048,
          "hidden_size": 128,
          "functional_group_size": 85,
          "mode": "regression",
          "model_dir": pretrain_dir,
      }
      model_config["task"] = "pretraining"
  
      pretrain_model = GroverModel(
          **model_config, device=torch.device("cpu")
      )
      pretrain_model._ensure_built()
      pretrain_model.save_checkpoint()
  
      model_config["task"] = "finetuning"
      model_config["model_dir"] = os.path.join(tmpdir, "finetune_model")
  
      finetune_model = GroverModel(
          **model_config, device=torch.device("cpu")
      )
      finetune_model._ensure_built()
  
      pm_e_sdict = pretrain_model.model.embedding.state_dict()
      fm_e_sdict = finetune_model.model.embedding.state_dict()
  
      # asserting that weights are not same before reloading
      for key in pm_e_sdict.keys():
          # notm and bias layers have constant weights, hence they are not checked
          if "norm" not in key and "bias" not in key:
              assert not torch.allclose(
                  pm_e_sdict[key], fm_e_sdict[key]
              )
  
      # acting - loading pretrained weights
      finetune_model.load_from_pretrained(
          source_model=pretrain_model, components=["embedding"]
      )
  
      fm_pretrained_e_sdict = (
          finetune_model.model.embedding.state_dict()
      )
  
      # asserting that weight matches after loading
      for key in pm_e_sdict.keys():
          assert torch.allclose(
              pm_e_sdict[key], fm_pretrained_e_sdict[key]
          )
  
file_path: deepchem/deepchem/models/torch_models/tests/test_grover.py
imports: import os
  import pytest
  import numpy
  import deepchem
label_desc: Use image node_id 9 for calling a global function with example usage: test_load_from_pretrained_embeddings(tmpdir) without return types