code: def test_batching_lengths(model_test, semiring, data):
      "Test batching"
      gen = Gen(model_test, data, LogSemiring)
      model, vals, N, batch = gen.model, gen.vals, gen.N, gen.batch
      lengths = torch.tensor(
          [
              data.draw(integers(min_value=2, max_value=N))
              for b in range(batch - 1)
          ]
          + [N]
      )
      # first way: batched implementation
      partition = model(semiring).logpartition(vals, lengths=lengths)[
          0
      ][0]
      # second way: unbatched implementation
      for b in range(batch):
          vals_b = vals[b : (b + 1), : (lengths[b] - 1)]
          lengths_b = lengths[b : (b + 1)]
          partition_b = model(semiring).logpartition(
              vals_b, lengths=lengths_b
          )[0][0]
          assert torch.isclose(partition[b], partition_b).all()
      # test _dp_standard
      partition_dp_standard = model(semiring)._dp_standard(
          vals, lengths=lengths
      )[0][0]
      assert torch.isclose(partition, partition_dp_standard).all()
  
imports: from torch_struct import CKY, CKY_CRF, DepTree, LinearChain, SemiMarkov, Alignment, deptree_nonproj, deptree_part
  from torch_struct import LogSemiring, CheckpointSemiring, CheckpointShardSemiring, KMaxSemiring, SparseMaxSemiring, MaxSemiring, StdSemiring, EntropySemiring
  from .extensions import LinearChainTest, SemiMarkovTest, DepTreeTest, CKYTest, CKY_CRFTest, test_lookup
  import torch
  from hypothesis import given
  from hypothesis.strategies import integers, data, sampled_from
  import pytest
  from hypothesis import settings
label_desc: Use image node_id 20 for calling a global function with example usage: test_batching_lengths(model_test, semiring, data) without return types