Skip to content

fix quant config issue & ui error issues#7

Merged
j4ys0n merged 5 commits into
mainfrom
claude/msquant-ui-quantization-011CUnDrUZLYgbNPBXZ8iKzY
Nov 4, 2025
Merged

fix quant config issue & ui error issues#7
j4ys0n merged 5 commits into
mainfrom
claude/msquant-ui-quantization-011CUnDrUZLYgbNPBXZ8iKzY

Conversation

@j4ys0n

@j4ys0n j4ys0n commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

No description provided.

Root Cause:
- NiceGUI's ui.number component returns float values by default
- The tokenizer's enable_truncation() expects max_length as integer
- This caused: TypeError: argument 'max_length': 'float' object
  cannot be interpreted as an integer

Changes:
- Convert max_seq_length to int in QuantizationConfig.__init__
- Also convert max_calib_samples to int for consistency

Impact:
- Tokenization will now succeed with proper integer max_length
- Both calibration parameters are guaranteed to be integers

Error path before fix:
UI (float) → QuantizationConfig (float) → oneshot (float)
→ tokenizer.enable_truncation(max_length=1024.0) → TypeError

After fix:
UI (float) → QuantizationConfig (int) → oneshot (int)
→ tokenizer.enable_truncation(max_length=1024) → Success
Issue:
- NiceGUI's ui.number component returns float values
- group_size from ui.number('Group Size', ...) returns float
- w_bit from ui.select should be int but converting for safety

Changes:
- Convert w_bit to int (line 42)
- Convert group_size to int (line 43)

All numeric parameters in QuantizationConfig now guaranteed to be integers:
✓ max_calib_samples (int)
✓ max_seq_length (int)
✓ w_bit (int)
✓ group_size (int)

This prevents potential type errors downstream in quantization libraries
that expect integer parameters.
Changes:
- Dataset Split: Changed from text input to editable select
  Options: ['train', 'test', 'validation', 'train[:512]', 'test[:512]']
  Added clearable prop (field is optional)

- Max Calibration Samples: Changed from number input to editable select
  Options: [128, 256, 512, 1024, 2048]
  Default: 256

- Max Sequence Length: Changed from number input to editable select
  Options: [512, 1024, 2048, 4096, 8192]
  Default: 2048

- Group Size: Changed from number input to editable select
  Options: [32, 64, 128, 256]
  Default: 128

Benefits:
✓ Users can pick from common values via dropdown
✓ Users can still type custom values (use-input prop)
✓ new-value-mode=add-unique allows adding typed values
✓ Guided defaults prevent invalid configurations
✓ Better UX than plain number/text inputs

All fields remain fully editable while providing sensible defaults.
Root Cause:
- ui.timer(2.0, update_status) calls update_status every 2 seconds
- update_status() showed notifications every time status was
  'failed', 'completed', or 'cancelled'
- No check to see if notification was already shown
- Result: 30+ duplicate "Job failed..." notifications

Changes:
- Added last_notified_status state dict to track:
  - Last notified status ('failed', 'completed', etc.)
  - Last notified message (error text, result, etc.)

- Updated notification logic:
  - 'completed': Only notify on first completion
  - 'failed': Only notify on first failure OR if error message changes
  - 'cancelled': Only notify on first cancellation
  - 'idle': Reset notification state (ready for next job)

Benefits:
✓ Each status change notifies exactly once
✓ Different error messages still trigger new notifications
✓ State resets when returning to idle
✓ No more notification spam
✓ User sees clean, non-repetitive status updates

Before: 30+ "Job failed..." notifications every 2 seconds
After: 1 "Job failed..." notification per failure
Copilot AI review requested due to automatic review settings November 4, 2025 07:05
@j4ys0n

j4ys0n commented Nov 4, 2025

Copy link
Copy Markdown
Contributor Author

Automated review 🤖

Summary of Changes
This PR addresses issues in the quantization configuration UI and job monitoring logic. It updates input fields in the configuration page to use dropdowns with predefined values for better UX and validation, and fixes a bug in the monitor page that caused repeated notifications. Additionally, it ensures type conversion for numeric fields in the quantization config to prevent runtime errors.

Key Changes & Positives

  • 🟢 Replaced ui.input with ui.select for dataset split, max calibration samples, max sequence length, and group size to enforce valid options and improve UX.
  • 🟢 Added last_notified_status tracking in monitor.py to prevent spamming notifications on repeated status updates.
  • 🟢 Type-casting numeric fields in config.py ensures values are integers, preventing potential runtime errors.

Potential Issues & Recommendations

  1. Issue / Risk: The ui.select components allow custom values via new-value-mode=add-unique, which may lead to invalid inputs if not validated downstream.
    Impact: Could cause runtime errors or unexpected behavior if invalid values are passed to quantization logic.
    Recommendation: Add validation in the quantization logic to reject invalid custom values or restrict input to predefined options only.
    Status: 🟡 Needs review

  2. Issue / Risk: The notification deduplication logic in monitor.py relies on last_notified_status being a shared state, which may not be thread-safe or persistent across sessions.
    Impact: Notifications may still be duplicated in multi-user or concurrent environments.
    Recommendation: Consider using a more robust mechanism like a timestamp-based deduplication or a centralized notification service.
    Status: 🟡 Needs review

  3. Issue / Risk: The max_calib_samples and max_seq_length fields in configure.py are now limited to predefined values, which may restrict flexibility for advanced users.
    Impact: Users may not be able to specify custom values outside the predefined list.
    Recommendation: Consider allowing custom values with validation or providing a note that only predefined values are supported.
    Status: 🟡 Needs review

Language/Framework Checks

  • Python: Type conversion in config.py is correct and safe. UI components in configure.py and monitor.py use appropriate Quasar/Streamlit patterns.
  • TypeScript/Node: Not present in this diff.
  • Go: Not present in this diff.
  • Java: Not present in this diff.
  • HCL/Terraform: Not present in this diff.
  • YAML/CI: Not present in this diff.
  • Docker: Not present in this diff.

Security & Privacy
No security or privacy concerns identified in this diff.

Build/CI & Ops
No build or ops changes in this diff.

Tests
No tests included in this diff. Consider adding unit tests for the new notification deduplication logic and validation of UI input values.

Approval Recommendation
Approve with caveats

  • Verify that the new ui.select components with new-value-mode=add-unique are properly validated in downstream logic.
  • Confirm that the notification deduplication logic is sufficient for concurrent environments or needs enhancement.
  • Ensure that the predefined value limitations for numeric fields are acceptable for all use cases.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the configuration UI by replacing numeric input fields with dropdown selects for better user experience, and prevents notification spam in the job monitor by tracking notification state.

  • Replaced manual input fields with dropdown selects for common configuration values
  • Added input validation by converting string inputs to integers in the QuantizationConfig constructor
  • Implemented notification deduplication to prevent repeated UI notifications for the same job status

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/msquant/core/quantizer/config.py Added int() conversions for numeric parameters to handle values from UI select components
src/msquant/app/pages/configure.py Replaced numeric inputs with select dropdowns for calibration and AWQ settings
src/msquant/app/pages/monitor.py Added notification state tracking to prevent duplicate notifications on status updates

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/msquant/core/quantizer/config.py Outdated
Comment on lines +38 to +39
self.max_calib_samples = int(max_calib_samples)
self.max_seq_length = int(max_seq_length)

Copilot AI Nov 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting parameters to int() without validation could raise ValueError for invalid input. Consider adding try-except blocks with clear error messages, or validate the input before conversion to provide better error handling for API consumers.

Copilot uses AI. Check for mistakes.
Comment thread src/msquant/core/quantizer/config.py Outdated
self.w_bit = w_bit
self.group_size = group_size
self.w_bit = int(w_bit)
self.group_size = int(group_size)

Copilot AI Nov 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting parameters to int() without validation could raise ValueError for invalid input. Consider adding try-except blocks with clear error messages, or validate the input before conversion to provide better error handling for API consumers.

Suggested change
self.group_size = int(group_size)
try:
self.group_size = int(group_size)
except (ValueError, TypeError):
raise ValueError(f"group_size must be an integer, got {group_size!r}")

Copilot uses AI. Check for mistakes.
ui.select(
['train', 'test', 'validation', 'train[:512]', 'test[:512]'],
value='train',
label='Dataset Split'

Copilot AI Nov 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The select component allows custom input via new-value-mode=add-unique, which means users can enter non-integer values. Combined with the int() conversion in config.py line 38-39, this could cause runtime errors when processing custom dataset split strings like 'train[:512]'. Consider validating the input or documenting that dataset split values are strings and should not be converted to integers.

Suggested change
label='Dataset Split'
label='Dataset Split (e.g., train, test, validation, or custom like train[:512])'

Copilot uses AI. Check for mistakes.
Comment on lines +79 to +88
ui.select(
[128, 256, 512, 1024, 2048],
value=256,
label='Max Calibration Samples'
).classes('flex-1').bind_value(form_data, 'max_calib_samples').props('use-input new-value-mode=add-unique')
ui.select(
[512, 1024, 2048, 4096, 8192],
value=2048,
label='Max Sequence Length'
).classes('flex-1').bind_value(form_data, 'max_seq_length').props('use-input new-value-mode=add-unique')

Copilot AI Nov 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new-value-mode=add-unique prop allows users to enter arbitrary string values. If a user enters a non-numeric value, the int() conversion in config.py (lines 38-39) will raise an uncaught ValueError. Consider adding input validation in the UI or in the start_quantization() error handler to provide user-friendly error messages.

Copilot uses AI. Check for mistakes.
Comment on lines +96 to +100
ui.select(
[32, 64, 128, 256],
value=128,
label='Group Size'
).classes('flex-1').bind_value(form_data, 'group_size').props('use-input new-value-mode=add-unique')

Copilot AI Nov 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new-value-mode=add-unique prop allows users to enter arbitrary string values. If a user enters a non-numeric value, the int() conversion in config.py (line 43) will raise an uncaught ValueError. Consider adding input validation in the UI or in the start_quantization() error handler to provide user-friendly error messages.

Copilot uses AI. Check for mistakes.
Type Annotation Fix:
- Added explicit type hint for last_notified_status dict
  Type: dict[str, str | None]
- Fixes Pyright errors about assigning strings to None type
- Properly declares that dict values can be str or None

Input Validation Fix:
- Wrapped all int() conversions in try-except blocks
- Added validation for positive values where appropriate
- Provides clear error messages for invalid inputs

Validation Details:
- max_calib_samples: Must be positive integer
- max_seq_length: Must be positive integer
- w_bit: Must be integer (range validated in validate())
- group_size: Must be positive integer

Error Messages:
- ValueError with descriptive message showing invalid value
- Catches both ValueError (bad string) and TypeError (None/invalid type)
- Original exception chained for debugging

Benefits:
✓ Prevents runtime errors from invalid user input
✓ UI allows custom values via editable combo boxes
✓ Clear error messages guide users to fix issues
✓ Type checker passes without errors
✓ Robust handling of edge cases (None, invalid strings, etc.)

Example error:
  Input: max_seq_length="abc"
  Error: Invalid max_seq_length value 'abc': must be a positive integer
@j4ys0n

j4ys0n commented Nov 4, 2025

Copy link
Copy Markdown
Contributor Author

Automated review 🤖

Summary of Changes
This PR addresses issues in the quantization configuration UI and job monitoring logic. It improves input validation for quantization parameters and prevents duplicate notifications in the monitor page. The changes also update UI components to use dropdowns with predefined values for better user experience and data consistency.

Key Changes & Positives

  • 🟢 Replaced ui.input with ui.select for dataset split, max calibration samples, max sequence length, and group size to enforce valid options and improve UX.
  • 🟢 Added logic in monitor.py to prevent spam notifications by tracking last notified status.
  • 🟢 Enhanced parameter validation in config.py with explicit type conversion and error handling for numeric fields.

Potential Issues & Recommendations

  1. Issue / Risk: The ui.select components in configure.py allow new values via new-value-mode=add-unique, which may lead to invalid or unexpected inputs if not validated downstream.
    Impact: Could cause runtime errors or incorrect behavior if user enters invalid values.
    Recommendation: Add input sanitization or validation in the backend to ensure only predefined values are accepted.
    Status: 🟡 Needs review

  2. Issue / Risk: The notification deduplication logic in monitor.py relies on string equality for messages, which might not be robust if error messages vary slightly.
    Impact: May still show duplicate notifications if messages differ slightly.
    Recommendation: Use a more robust deduplication mechanism, such as hashing or status+message tuples.
    Status: 🟡 Needs review

  3. Issue / Risk: The validation in config.py does not handle cases where max_calib_samples or max_seq_length are passed as strings that cannot be converted to integers.
    Impact: Could raise unhandled exceptions if invalid strings are passed.
    Recommendation: Add a fallback default value or more graceful error handling.
    Status: 🔴 Problem

Language/Framework Checks

  • Python:
    • ✅ Proper use of try/except blocks for type conversion.
    • ✅ Logging and error handling aligned with Python best practices.
    • � Minor: Consider using int() with default fallback instead of raising exceptions for better UX.

Security & Privacy

  • No direct security concerns introduced.
  • Input validation is improved, reducing risk of injection or malformed data.

Build/CI & Ops

  • No changes to build or deployment logic.
  • Ensure UI changes are tested across browsers and devices.

Tests

  • Add unit tests for config.py validation logic to cover edge cases like invalid strings, negative numbers, and None values.
  • Add integration tests for monitor.py notification deduplication logic.

Approval Recommendation
Approve with caveats

  • Verify that ui.select new value mode behavior is acceptable or needs restriction.
  • Confirm that notification deduplication logic is robust enough for production use.
  • Add tests for config validation edge cases.

@j4ys0n
j4ys0n merged commit 6301077 into main Nov 4, 2025
1 check passed
@j4ys0n
j4ys0n deleted the claude/msquant-ui-quantization-011CUnDrUZLYgbNPBXZ8iKzY branch November 4, 2025 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants