@@ -1642,6 +1642,26 @@ def build_tensor_scale(dtype: ir.DataType = ir.DataType.FLOAT) -> PolicyComponen
16421642 return _component ("mobius.policy.auxiliary@1" , graph , {})
16431643
16441644
1645+ def build_tensor_clamp (
1646+ dtype : ir .DataType = ir .DataType .FLOAT ,
1647+ * ,
1648+ minimum : float ,
1649+ maximum : float ,
1650+ ) -> PolicyComponent :
1651+ """Clamp a rank-4 tensor to an explicitly declared numeric range."""
1652+ graph , builder = _make_graph ("tensor_clamp" )
1653+ op = builder .op
1654+ tensor = builder .input ("tensor" , dtype , ["batch" , "channels" , "height" , "width" ])
1655+ clamped = op .Clip (
1656+ tensor ,
1657+ op .Cast (op .Constant (value_float = minimum ), to = dtype ),
1658+ op .Cast (op .Constant (value_float = maximum ), to = dtype ),
1659+ )
1660+ clamped .shape = tensor .shape
1661+ builder .add_output (clamped , "clamped" )
1662+ return _component ("mobius.policy.auxiliary@1" , graph , {})
1663+
1664+
16451665def build_zeros_like (dtype : ir .DataType = ir .DataType .FLOAT ) -> PolicyComponent :
16461666 """Produce a zero tensor shaped like its reference, for state initializers."""
16471667 graph , builder = _make_graph ("zeros_like" )
@@ -1785,11 +1805,69 @@ def build_image_grid_positions(
17851805 return _component ("mobius.policy.auxiliary@1" , graph , {})
17861806
17871807
1808+ def build_image_dimensions (
1809+ dtype : ir .DataType = ir .DataType .FLOAT ,
1810+ ) -> PolicyComponent :
1811+ """Read pixel height and width from a rank-4 image tensor."""
1812+ graph , builder = _make_graph ("image_dimensions" )
1813+ op = builder .op
1814+ tensor = builder .input ("tensor" , dtype , ["batch" , "channels" , "height" , "width" ])
1815+ height = op .Shape (tensor , start = 2 , end = 3 )
1816+ width = op .Shape (tensor , start = 3 , end = 4 )
1817+ height .shape = width .shape = ir .Shape ([1 ])
1818+ builder .add_output (height , "height" )
1819+ builder .add_output (width , "width" )
1820+ return _component ("mobius.policy.auxiliary@1" , graph , {})
1821+
1822+
17881823_RNG_MODULUS = 2147483647
17891824_RNG_MULTIPLIER = 48271
17901825_RNG_STRIDE = 2654435761
17911826
17921827
1828+ def build_image_noise_geometry (
1829+ * ,
1830+ channels : int = 3 ,
1831+ token_stride : int = 32 ,
1832+ base_image_sequence_length : int = 64 ,
1833+ noise_scale : float = 1.0 ,
1834+ maximum_noise_scale : float = 16.0 ,
1835+ ) -> PolicyComponent :
1836+ """Derive image-noise shape, token grid, and resolution-dependent scale."""
1837+ graph , builder = _make_graph ("image_noise_geometry" )
1838+ op = builder .op
1839+ height = builder .input ("height" , ir .DataType .INT64 , [1 ])
1840+ width = builder .input ("width" , ir .DataType .INT64 , [1 ])
1841+
1842+ row_shape = op .Concat (
1843+ op .Constant (value_ints = [channels ]),
1844+ height ,
1845+ width ,
1846+ axis = 0 ,
1847+ )
1848+ row_shape .shape = ir .Shape ([3 ])
1849+ token_height = op .Div (height , op .Constant (value_int = token_stride ))
1850+ token_width = op .Div (width , op .Constant (value_int = token_stride ))
1851+ token_height .shape = token_width .shape = ir .Shape ([1 ])
1852+
1853+ image_sequence_length = op .Mul (token_height , token_width )
1854+ relative_length = op .Div (
1855+ op .Cast (image_sequence_length , to = ir .DataType .FLOAT ),
1856+ op .Constant (value_float = float (base_image_sequence_length )),
1857+ )
1858+ resolved_scale = op .Min (
1859+ op .Mul (op .Sqrt (relative_length ), op .Constant (value_float = noise_scale )),
1860+ op .Constant (value_float = maximum_noise_scale ),
1861+ )
1862+ resolved_scale .shape = ir .Shape ([1 ])
1863+
1864+ builder .add_output (row_shape , "row_shape" )
1865+ builder .add_output (token_height , "token_height" )
1866+ builder .add_output (token_width , "token_width" )
1867+ builder .add_output (resolved_scale , "noise_scale" )
1868+ return _component ("mobius.policy.auxiliary@1" , graph , {})
1869+
1870+
17931871def _counter_uniform (op , key , counter ):
17941872 """Map a counter-based ``(key, counter)`` pair onto a uniform in ``(0, 1)``.
17951873
0 commit comments