11"""
2- Copyright 2024 Google LLC
2+ Copyright 2026 Google LLC
33
44Licensed under the Apache License, Version 2.0 (the "License");
55you may not use this file except in compliance with the License.
1919
2020
2121def print_device_memory_info (devices ):
22+ """Prints information about JAX devices.
23+
24+ Args:
25+ devices: The JAX device or list of jax.Device to print information about.
26+ """
2227 if not isinstance (devices , list ):
2328 devices = [devices ]
2429
@@ -35,14 +40,24 @@ def print_device_memory_info(devices):
3540
3641
3742def print_array_info (array , name ):
43+ """Prints information about a JAX array.
44+
45+ Note: This function is intended for use with concrete JAX arrays outside of
46+ JIT-compiled contexts. Calling this function inside a `@jax.jit` (or similar)
47+ context will fail because `array` will be a Tracer object, which does not
48+ have attributes like `is_fully_replicated` or `device_buffers`.
49+
50+ Args:
51+ array: The JAX array (jax.Array) to print information about.
52+ name: (str) A name to identify the array in the output.
53+ """
3854 print ("**** name: " , name )
3955 jax .debug .print ("dtype: {x}" , x = array .dtype )
4056 jax .debug .print ("shape: {x}" , x = array .shape )
4157 jax .debug .print ("is fully replicated: {x}" , x = array .is_fully_replicated )
42- num_devices = jax .device_count ()
43- for device_idx in num_devices :
44- jax .debug .print ("shape on device {x} : {y}" , x = device_idx , y = array .device_buffers [0 ].shape )
45- jax .debug .print ("size on device {x} : {y}" , x = device_idx , y = array .device_buffers [device_idx ].size / array .size )
58+ for device_idx , buffer in enumerate (array .device_buffers ):
59+ jax .debug .print ("shape on device {x} : {y}" , x = device_idx , y = buffer .shape )
60+ jax .debug .print ("size on device {x} : {y}" , x = device_idx , y = buffer .size / array .size )
4661
4762
4863class TpuType (Enum ):
0 commit comments