mirror of https://github.com/bmaltais/kohya_ss
Fix(tensorboard): Check for executable to prevent crash
I replaced the direct import of `tensorflow` with a check for the `tensorboard` executable. This resolves the `illegal hardware instruction` crash that occurred on systems with CPUs lacking AVX2 support. The new implementation ensures that the TensorBoard feature remains available if the `tensorboard` command is in the system's PATH, without causing a fatal error when the `tensorflow` library is incompatible with the underlying hardware.pull/3343/head
parent
4161d1d80a
commit
f6f3f35329
|
|
@ -3,12 +3,15 @@ import gradio as gr
|
|||
import subprocess
|
||||
import time
|
||||
import webbrowser
|
||||
import shutil
|
||||
|
||||
try:
|
||||
os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0"
|
||||
import tensorflow # Attempt to import tensorflow to check if it is installed
|
||||
|
||||
visibility = True
|
||||
# os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0"
|
||||
# import tensorflow # Attempt to import tensorflow to check if it is installed
|
||||
if shutil.which("tensorboard"):
|
||||
visibility = True
|
||||
else:
|
||||
visibility = False
|
||||
except ImportError:
|
||||
visibility = False
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
import unittest
|
||||
from unittest.mock import patch
|
||||
import importlib
|
||||
|
||||
class TestTensorboardVisibility(unittest.TestCase):
|
||||
|
||||
@patch('shutil.which', return_value='/usr/bin/tensorboard')
|
||||
def test_tensorboard_visibility_when_tensorboard_is_present(self, mock_which):
|
||||
import kohya_gui.class_tensorboard
|
||||
importlib.reload(kohya_gui.class_tensorboard)
|
||||
self.assertTrue(kohya_gui.class_tensorboard.visibility)
|
||||
|
||||
@patch('shutil.which', return_value=None)
|
||||
def test_tensorboard_visibility_when_tensorboard_is_absent(self, mock_which):
|
||||
import kohya_gui.class_tensorboard
|
||||
importlib.reload(kohya_gui.class_tensorboard)
|
||||
self.assertFalse(kohya_gui.class_tensorboard.visibility)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Reference in New Issue