code: def test_load_from_state_dict_adapter(
      self, encoder_config: LLMEncoderConfig, adapter: str, wrap: bool
  ):
      def weights_init(m):
          """Reinitialize the weights of a torch module."""
          if hasattr(m, "weight") and m.weight.ndim > 1:
              torch.nn.init.xavier_uniform_(m.weight.data)
  
      # Update the config with an adapter
      encoder_config_with_adapter = (
          self.create_encoder_config_with_adapter(
              encoder_config, adapter
          )
      )
  
      # Create two encoders from the same config
      encoder1 = LLMEncoder(encoder_config=encoder_config_with_adapter)
      encoder2 = LLMEncoder(encoder_config=encoder_config_with_adapter)
  
      # Initialize the adapters
      encoder1.prepare_for_training()
      encoder2.prepare_for_training()
  
      if wrap:
          encoder1 = WrapperModule(encoder1)
          encoder2 = WrapperModule(encoder2)
  
      encoder2.apply(weights_init)
  
      encoder1_sd = encoder1.state_dict()
      encoder2_sd = encoder2.state_dict()
      adapter_keys = [
          k
          for k in encoder1_sd.keys()
          if "lora_" in k and "weight" in k
      ]
      model_keys = [k for k in encoder1_sd.keys() if "lora_" not in k]
  
      # The LoRA weights should no longer be equal
      assert all(
          map(
              lambda k: not torch.equal(encoder1_sd[k], encoder2_sd[k]),
              adapter_keys,
          )
      )
  
      # The remaining weights should also no longer be equal
      assert all(
          map(
              lambda k: not torch.equal(encoder1_sd[k], encoder2_sd[k]),
              model_keys,
          )
      )
  
      # Load the weights of encoder1 back into encoder2
      encoder2.load_state_dict(encoder1_sd)
      encoder2_sd = encoder2.state_dict()
  
      # The LoRA weights should now be equal again
      assert all(
          map(
              lambda k: torch.equal(encoder1_sd[k], encoder2_sd[k]),
              adapter_keys,
          )
      )
  
      # The remaining weights should still be unequal
      assert all(
          map(
              lambda k: not torch.equal(encoder1_sd[k], encoder2_sd[k]),
              model_keys,
          )
      )
  
imports: import copy
  import pytest
  import torch
  import torch.nn
  from transformers import AutoConfig, PreTrainedModel
  from ludwig.encoders.text_encoders import LLMEncoder
  from ludwig.schema.encoders.text_encoders import LLMEncoderConfig
  from ludwig.schema.llms.peft import BaseAdapterConfig, LoraConfig
  from ludwig.utils.llm_utils import get_context_len
label_desc: Use image node_id 8 for calling the TestLLMEncoder obj's underlying member method code with example usage: obj.test_load_from_state_dict_adapter(encoder_config, adapter, wrap) without return types