From 48454ced5e06acde7e1da9111620e5776dfb3089 Mon Sep 17 00:00:00 2001 From: huongdm1896 <domaihuong1451997@gmail.com> Date: Fri, 25 Apr 2025 19:57:45 +0200 Subject: [PATCH] update client code --- Flower_v1/client_2.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Flower_v1/client_2.py b/Flower_v1/client_2.py index cd8b56e..04a135a 100644 --- a/Flower_v1/client_2.py +++ b/Flower_v1/client_2.py @@ -9,18 +9,24 @@ import numpy as np import sys import random +# list up physical_devices = tf.config.list_physical_devices('GPU') -if physical_devices: + +if len(physical_devices) > 0: + # Only use 1st GPU + tf.config.set_visible_devices(physical_devices[0], 'GPU') + + # Avoid over mem tf.config.experimental.set_memory_growth(physical_devices[0], True) - print("GPU detected and memory growth enabled.") + print("GPU detected and memory growth enabled. Using GPU:", physical_devices[0].name) else: print("No GPU detected, using CPU.") # Set random seed for reproducibility def set_random_seed(seed): - random.seed(seed) # Python random module seed - np.random.seed(seed) # Numpy random seed - tf.random.set_seed(seed) # TensorFlow random seed + random.seed(seed) + np.random.seed(seed) + tf.random.set_seed(seed) # Set a specific seed value set_random_seed(42) -- GitLab