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

Function is_oom

src/MaxText/train_compile.py:147–194  ·  view source on GitHub ↗

Function returns a boolean indicating whether OOM happens

(argv: Sequence[str])

Source from the content-addressed store, hash-verified

145
146
147def is_oom(argv: Sequence[str]) -> bool:
148 """Function returns a boolean indicating whether OOM happens"""
149 # Parse and validate configuration
150 config = pyconfig.initialize(argv)
151 validate_config(config)
152
153 # Create target mesh
154 topology_mesh = get_topology_mesh(config)
155
156 # Print system information after building the compile topology to avoid
157 # prematurely initializing the backend.
158 max_utils.print_system_information()
159
160 # Get shaped inputs
161 shaped_train_args, shaped_train_kwargs, state_mesh_shardings, model = get_shaped_inputs(topology_mesh, config)
162
163 # Get data sharding
164 data_sharding = sharding.get_input_data_sharding(config, topology_mesh)
165
166 # Get function to compile and shardings
167 func_to_compile, in_shard, out_shard, static_argnums, donate_argnums = (
168 maxtext_utils.get_functional_train_with_signature(
169 train.train_step, data_sharding, state_mesh_shardings, model, config
170 )
171 )
172
173 try:
174 _ = jit_and_compile(
175 func_to_compile,
176 shaped_train_args,
177 shaped_train_kwargs,
178 topology_mesh,
179 in_shard,
180 out_shard,
181 static_argnums,
182 donate_argnums,
183 nn_partitioning.axis_rules(config.logical_axis_rules),
184 )
185 return False
186 except Exception as e:
187 # return true if OOM error happens
188 # OOM error looks like
189 # jax.errors.JaxRuntimeError: RESOURCE_EXHAUSTED: Allocation ...
190 # jax.errors.JaxRuntimeError: INTERNAL: RET_CHECK failure ...
191 message = str(e).lower()
192 if "resource_exhausted" in message or "hbm" in message:
193 return True
194 raise e
195
196
197def main(argv: Sequence[str]) -> None:

Callers

nothing calls this directly

Calls 5

get_topology_meshFunction · 0.85
get_shaped_inputsFunction · 0.85
jit_and_compileFunction · 0.85
validate_configFunction · 0.70
initializeMethod · 0.45

Tested by

no test coverage detected