Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modifications to support Habana Gaudi HPUs
- Loading branch information
Ubuntu
committed
Oct 28, 2023
1 parent
5ef669d
commit 385309d
Showing
7 changed files
with
204 additions
and
40 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,6 @@ | ||
export LOG_LEVEL_PT_FALLBACK=1 | ||
export ENABLE_CONSOLE=true | ||
export LOG_LEVEL_ALL=4 | ||
export GPU_MIGRATION_LOG_LEVEL=3 | ||
export PT_HPU_ENABLE_LAZY_COLLECTIVES=true | ||
#export PT_HPU_LAZY_MODE=1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import torch | ||
import habana_frameworks.torch.hpu.random as htrandom | ||
|
||
class HPUGenerator: | ||
def __init__(self): | ||
self.state = htrandom.get_rng_state() | ||
self.initial_seed_value = htrandom.initial_seed() | ||
|
||
def get_state(self): | ||
# PyTorch’s Generator.get_state returns a tensor, same as htrandom.get_rng_state | ||
return htrandom.get_rng_state() | ||
|
||
def set_state(self, state): | ||
htrandom.set_rng_state(state) | ||
self.state = state | ||
|
||
def manual_seed(self, seed): | ||
htrandom.manual_seed(seed) | ||
self.initial_seed_value = seed | ||
self.state = htrandom.get_rng_state() | ||
return self | ||
|
||
def seed(self): | ||
# Assuming htrandom.seed generates a new seed internally and sets it | ||
htrandom.seed() | ||
self.state = htrandom.get_rng_state() | ||
self.initial_seed_value = htrandom.initial_seed() # Update initial_seed based on new state | ||
|
||
def initial_seed(self): | ||
return self.initial_seed_value | ||
|
||
# Usage Example | ||
#generator = HPUGenerator() | ||
#state = generator.get_state() | ||
#print(f"Initial State: {state}") | ||
# | ||
#generator.set_state(state) | ||
#print("State is set back to its initial value.") | ||
# | ||
#generator.manual_seed(42) | ||
#print(f"Manual Seed: {generator.initial_seed()}") | ||
# | ||
#generator.seed() | ||
#print(f"Seed is set to a new value. New Initial Seed: {generator.initial_seed()}") | ||
|
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
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