Skip to content

Commit

Permalink
feat(config): add configuration options
Browse files Browse the repository at this point in the history
- add more configuration options for AUTOGGUF_MODEL_DIR_NAME, AUTOGGUF_OUTPUT_DIR_NAME, and AUTOGGUF_RESIZE_FACTOR (these get created on startup)
- move some UI helper funtions out of AutoGGUF.py and into ui_update and Ta
- optimize imports for utility classes
- fix some missing imports
  • Loading branch information
leafspark committed Aug 25, 2024
1 parent 86d7bbb commit fec22ad
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 80 deletions.
51 changes: 16 additions & 35 deletions src/AutoGGUF.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,20 @@ def __init__(self, args: List[str]) -> None:

load_dotenv() # Loads the .env file

self.resize_factor = 1.1 # 10% increase/decrease
# Configuration
self.model_dir_name = os.environ.get("AUTOGGUF_MODEL_DIR_NAME", "models")
self.output_dir_name = os.environ.get(
"AUTOGGUF_OUTPUT_DIR_NAME", "quantized_models"
)

self.resize_factor = float(
os.environ.get("AUTOGGUF_RESIZE_FACTOR", 1.1)
) # 10% increase/decrease
self.default_width, self.default_height = self.parse_resolution()
self.resize(self.default_width, self.default_height)

ensure_directory(os.path.abspath("quantized_models"))
ensure_directory(os.path.abspath("models"))
ensure_directory(os.path.abspath(self.output_dir_name))
ensure_directory(os.path.abspath(self.model_dir_name))

# References
self.update_base_model_visibility = partial(
Expand Down Expand Up @@ -85,6 +93,9 @@ def __init__(self, args: List[str]) -> None:
self.browse_imatrix = utils.browse_imatrix.__get__(self)
self.get_models_data = utils.get_models_data.__get__(self)
self.get_tasks_data = utils.get_tasks_data.__get__(self)
self.cancel_task = partial(TaskListItem.cancel_task, self)
self.delete_task = partial(TaskListItem.delete_task, self)
self.toggle_gpu_offload_auto = partial(ui_update.toggle_gpu_offload_auto, self)
self.update_threads_spinbox = partial(ui_update.update_threads_spinbox, self)
self.update_threads_slider = partial(ui_update.update_threads_slider, self)
self.update_gpu_offload_spinbox = partial(
Expand Down Expand Up @@ -238,7 +249,7 @@ def __init__(self, args: List[str]) -> None:

# Models path
models_layout = QHBoxLayout()
self.models_input = QLineEdit(os.path.abspath("models"))
self.models_input = QLineEdit(os.path.abspath(self.model_dir_name))
models_button = QPushButton(BROWSE)
models_button.clicked.connect(self.browse_models)
models_layout.addWidget(QLabel(MODELS_PATH))
Expand All @@ -248,7 +259,7 @@ def __init__(self, args: List[str]) -> None:

# Output path
output_layout = QHBoxLayout()
self.output_input = QLineEdit(os.path.abspath("quantized_models"))
self.output_input = QLineEdit(os.path.abspath(self.output_dir_name))
output_button = QPushButton(BROWSE)
output_button.clicked.connect(self.browse_output)
output_layout.addWidget(QLabel(OUTPUT_PATH))
Expand Down Expand Up @@ -1196,11 +1207,6 @@ def show_task_properties(self, item) -> None:
model_info_dialog.exec()
break

def toggle_gpu_offload_auto(self, state) -> None:
is_auto = state == Qt.CheckState.Checked
self.gpu_offload_slider.setEnabled(not is_auto)
self.gpu_offload_spinbox.setEnabled(not is_auto)

def cancel_task_by_item(self, item) -> None:
task_item = self.task_list.itemWidget(item)
for thread in self.quant_threads:
Expand All @@ -1210,31 +1216,6 @@ def cancel_task_by_item(self, item) -> None:
self.quant_threads.remove(thread)
break

def cancel_task(self, item) -> None:
self.logger.info(CANCELLING_TASK.format(item.text()))
self.cancel_task_by_item(item)

def delete_task(self, item) -> None:
self.logger.info(DELETING_TASK.format(item.text()))

# Cancel the task first
self.cancel_task_by_item(item)

reply = QMessageBox.question(
self,
CONFIRM_DELETION_TITLE,
CONFIRM_DELETION,
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
QMessageBox.StandardButton.No,
)
if reply == QMessageBox.StandardButton.Yes:
task_item = self.task_list.itemWidget(item)
row = self.task_list.row(item)
self.task_list.takeItem(row)

if task_item:
task_item.deleteLater()

def create_label(self, text, tooltip) -> QLabel:
label = QLabel(text)
label.setToolTip(tooltip)
Expand Down
2 changes: 1 addition & 1 deletion src/DownloadThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import zipfile

import requests
from PySide6.QtCore import *
from PySide6.QtCore import QThread, Signal


class DownloadThread(QThread):
Expand Down
2 changes: 1 addition & 1 deletion src/ModelInfoDialog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PySide6.QtWidgets import *
from PySide6.QtWidgets import QVBoxLayout, QTextEdit, QDialog, QPushButton


class ModelInfoDialog(QDialog):
Expand Down
5 changes: 3 additions & 2 deletions src/QuantizationThread.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import signal
import subprocess

from PySide6.QtCore import *
from PySide6.QtCore import Signal, QThread

from imports_and_globals import open_file_safe
from Localizations import *
from Localizations import IN_PROGRESS, COMPLETED


class QuantizationThread(QThread):
Expand Down
32 changes: 32 additions & 0 deletions src/TaskListItem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from PySide6.QtCore import *
from PySide6.QtWidgets import *

from Localizations import (
DELETING_TASK,
CANCELLING_TASK,
CONFIRM_DELETION_TITLE,
CONFIRM_DELETION,
)


class TaskListItem(QWidget):
def __init__(
Expand Down Expand Up @@ -30,6 +37,31 @@ def __init__(
self.progress_timer.timeout.connect(self.update_progress)
self.progress_value = 0

def cancel_task(self, item) -> None:
self.logger.info(CANCELLING_TASK.format(item.text()))
self.cancel_task_by_item(item)

def delete_task(self, item) -> None:
self.logger.info(DELETING_TASK.format(item.text()))

# Cancel the task first
self.cancel_task_by_item(item)

reply = QMessageBox.question(
self,
CONFIRM_DELETION_TITLE,
CONFIRM_DELETION,
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
QMessageBox.StandardButton.No,
)
if reply == QMessageBox.StandardButton.Yes:
task_item = self.task_list.itemWidget(item)
row = self.task_list.row(item)
self.task_list.takeItem(row)

if task_item:
task_item.deleteLater()

def update_status(self, status) -> None:
self.status = status
self.status_label.setText(status)
Expand Down
35 changes: 0 additions & 35 deletions src/imports_and_globals.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,9 @@
import os
import sys
from typing import TextIO, Union

import psutil
import subprocess
import time
import signal
import json
import platform
import requests
import zipfile
from datetime import datetime
from PySide6.QtWidgets import (
QApplication,
QMainWindow,
QVBoxLayout,
QHBoxLayout,
QWidget,
QPushButton,
QListWidget,
QLineEdit,
QLabel,
QFileDialog,
QProgressBar,
QComboBox,
QTextEdit,
QCheckBox,
QGroupBox,
QFormLayout,
QScrollArea,
QSlider,
QSpinBox,
QListWidgetItem,
QMessageBox,
QDialog,
QPlainTextEdit,
QMenu,
)
from PySide6.QtCore import QTimer, Signal, QThread, Qt, QSize
from PySide6.QtGui import QCloseEvent, QAction

from Localizations import *

Expand Down
13 changes: 12 additions & 1 deletion src/presets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import json

from PySide6.QtCore import Qt
from PySide6.QtWidgets import QFileDialog, QMessageBox
from Localizations import *
from Localizations import (
SAVING_PRESET,
SAVE_PRESET,
JSON_FILES,
PRESET_SAVED,
PRESET_SAVED_TO,
LOADING_PRESET,
LOAD_PRESET,
PRESET_LOADED,
PRESET_LOADED_FROM,
)


def save_preset(self) -> None:
Expand Down
7 changes: 7 additions & 0 deletions src/ui_update.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from PySide6.QtCore import QTimer
from PySide6.QtGui import Qt

from Localizations import *
import psutil
from error_handling import show_error


def toggle_gpu_offload_auto(self, state) -> None:
is_auto = state == Qt.CheckState.Checked
self.gpu_offload_slider.setEnabled(not is_auto)
self.gpu_offload_spinbox.setEnabled(not is_auto)


def update_model_info(logger, self, model_info) -> None:
logger.debug(UPDATING_MODEL_INFO.format(model_info))
pass
Expand Down
9 changes: 4 additions & 5 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from typing import Any, Dict, List, Union
from typing import Any, Union

import requests
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QFileDialog

from error_handling import show_error
from Localizations import *
import requests

from DownloadThread import DownloadThread
from Localizations import *
from error_handling import show_error
from imports_and_globals import ensure_directory


Expand Down

0 comments on commit fec22ad

Please sign in to comment.