-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add Jax support in CUDA sync and
ZeusMonitor
(#97)
Co-authored-by: Jae-Won Chung <[email protected]>
- Loading branch information
1 parent
defed56
commit 37cfa1d
Showing
3 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import time | ||
import jax | ||
import jax.numpy as jnp | ||
from zeus.monitor import ZeusMonitor | ||
|
||
@jax.jit | ||
def mat_prod(B): | ||
""" Dummy example to make GPU warm with a jitting""" | ||
A = jnp.ones((1000, 1000)) | ||
return A @ B | ||
|
||
if __name__ == "__main__": | ||
# Time/Energy measurements for four GPUs will begin and end at the same time. | ||
gpu_indices = [0] | ||
|
||
monitor = ZeusMonitor(gpu_indices=gpu_indices, backend="jax") | ||
|
||
# Mark the beginning of a measurement window. You can use any string | ||
# as the window name, but make sure it's unique. | ||
monitor.begin_window("all_computations") | ||
|
||
# Actual work | ||
key = jax.random.PRNGKey(0) | ||
B = jax.random.uniform(key, (1000, 1000)) | ||
for i in range(100): | ||
B = mat_prod(B) | ||
|
||
# Mark the end of a measurement window and retrieve the measurment result. | ||
result = monitor.end_window("all_computations") | ||
|
||
# Print the measurement result. | ||
print(f"Training took {result.time} seconds.") | ||
print(f"Training consumed {result.total_energy} Joules.") | ||
for gpu_idx, gpu_energy in result.gpu_energy.items(): | ||
print(f"GPU {gpu_idx} consumed {gpu_energy} Joules.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters