code: def test_parts_from_sequence(model_test, data):
      gen = Gen(model_test, data, LogSemiring)
      C = gen.vals.size(-1)
      if isinstance(gen.struct, LinearChain):
          K = 2
          background = 0
          extra = C
      elif isinstance(gen.struct, SemiMarkov):
          K = gen.vals.size(-3)
          background = -1
          extra = C, K
      else:
          raise NotImplementedError()
  
      sequence = torch.full((gen.batch, gen.N), background, dtype=int)
      for b in range(gen.batch):
          i = 0
          while i < gen.N:
              symbol = torch.randint(0, C, (1,)).item()
              sequence[b, i] = symbol
              length = torch.randint(1, K, (1,)).item()
              i += length
  
      edge = gen.model.to_parts(sequence, extra)
      sequence_, extra_ = gen.model.from_parts(edge)
      assert extra == extra_, (extra, extra_)
      assert (torch.isclose(sequence, sequence_)).all(), (
          sequence - sequence_
      )
      edge_ = gen.model.to_parts(sequence_, extra_)
      assert (torch.isclose(edge, edge_)).all(), edge - edge_
  
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 10 for calling a global function with example usage: test_parts_from_sequence(model_test, data) without return types