Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Set deterministic behavior for cuDNN in HFTrainer #879

davidmezzettiba552d5a3f9d
diff --git a/src/python/txtai/pipeline/train/hftrainer.py b/src/python/txtai/pipeline/train/hftrainer.py
index 04f06dc1..9d493a9d 100644
--- a/src/python/txtai/pipeline/train/hftrainer.py
+++ b/src/python/txtai/pipeline/train/hftrainer.py
@@ -89,8 +89,8 @@ class HFTrainer(Tensors):
# Parse TrainingArguments
args = self.parse(args)
- # Set seed for model reproducibility
- set_seed(args.seed)
+ # Initialize torch parameters for reproducibility
+ self.initialize(args.seed)
# Load model configuration, tokenizer and max sequence length
config, tokenizer, maxlength = self.load(base, maxlength)
@@ -155,20 +155,28 @@ class HFTrainer(Tensors):
"""
# Default training arguments
- args = {
- "output_dir": "",
- "save_strategy": "no",
- "report_to": "none",
- "log_level": "warning",
- "use_cpu": not Models.hasaccelerator(),
- "full_determinism": True,
- }
+ args = {"output_dir": "", "save_strategy": "no", "report_to": "none", "log_level": "warning", "use_cpu": not Models.hasaccelerator()}
# Apply custom arguments
args.update(updates)
return TrainingArguments(**args)
+ def initialize(self, seed):
+ """
+ Initializes torch parameters to ensure reproducibility.
+
+ Args:
+ seed: seed to set
+ """
+
+ # Set seed for model reproducibility
+ set_seed(seed)
+
+ # Enable cuDNN deterministic mode
+ torch.backends.cudnn.deterministic = True
+ torch.backends.cudnn.benchmark = False
+
def load(self, base, maxlength):
"""
Loads the base config and tokenizer.