MCPcopy Create free account
hub / github.com/AI-Hypercomputer/maxtext / write_packed_example

Function write_packed_example

src/MaxText/sequence_packing.py:114–123  ·  view source on GitHub ↗
(partial, outputs)

Source from the content-addressed store, hash-verified

112 keys_etc = empty_example.keys()
113
114 def write_packed_example(partial, outputs):
115 new_partial = empty_example.copy()
116 new_outputs = {}
117 for k in keys_etc:
118 # use pad_id to pad inputs/targets, use 0 to pad *_position
119 pad_id_to_use = 0 if len(k.split("_")) > 1 else pad_id
120 new_outputs[k] = outputs[k].write(
121 outputs[k].size(), tf.pad(partial[k], [[0, key2length[k] - tf.size(partial[k])]], constant_values=pad_id_to_use)
122 )
123 return new_partial, new_outputs
124
125 def map_fn(x):
126 """Internal function to flat_map over.

Callers 2

false_fnFunction · 0.85
map_fnFunction · 0.85

Calls 2

copyMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected