code: def test_parts_from_marginals(model_test, data):
      gen = Gen(model_test, data, MaxSemiring)
  
      edge = gen.struct.marginals(gen.vals).long()
      sequence, extra = gen.model.from_parts(edge)
      edge_ = gen.model.to_parts(sequence, extra)
  
      assert (torch.isclose(edge, edge_)).all(), edge - edge_
  
      sequence_, extra_ = gen.model.from_parts(edge_)
      assert extra == extra_, (extra, extra_)
      assert (torch.isclose(sequence, sequence_)).all(), (
          sequence - sequence_
      )
  
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 9 for calling a global function with example usage: test_parts_from_marginals(model_test, data) without return types