code: def test_collect_weights(tmpdir, csv_filename):
      output_dir = None
      try:
          model, output_dir = _train(*_prepare_data(csv_filename))
          model_path = os.path.join(output_dir, "model")
  
          # 1 for the encoder (embeddings).
          # 2 for the decoder classifier (w and b).
          weights = [w for _, w in model.model.collect_weights()]
          assert len(weights) == 3
  
          # Load model from disk to ensure correct weight names
          model_loaded = LudwigModel.load(model_path)
          tensor_names = [
              name for name, w in model_loaded.collect_weights()
          ]
          assert len(tensor_names) == 3
  
          filenames = collect_weights(model_path, tensor_names, tmpdir)
          assert len(filenames) == 3
  
          for weight, filename in zip(weights, filenames):
              saved_weight = np.load(filename)
              assert torch.allclose(
                  weight,
                  torch.from_numpy(saved_weight).to(DEVICE),
                  rtol=1.0e-4,
              ), filename
      finally:
          if output_dir:
              shutil.rmtree(output_dir, ignore_errors=True)
  
file_path: ludwig/tests/integration_tests/test_collect.py
imports: import os
  import shutil
  import numpy
  import torch
  from ludwig.api import LudwigModel
  from ludwig.collect import collect_activations, collect_weights, print_model_summary
  from ludwig.constants import BATCH_SIZE, ENCODER, TRAINER, TYPE
  from ludwig.utils.torch_utils import get_torch_device
  from tests.integration_tests.utils import category_feature, ENCODERS, generate_data, sequence_feature
label_desc: Use image node_id 5 for calling a global function with example usage: test_collect_weights(tmpdir, csv_filename) without return types