Skip to content

QuantizationMode should be algebraic instead of scalar #285

@AppAppWorks

Description

@AppAppWorks

Previously MLX supported affine quantization only, it was fine to have groupSize and bits as separate arguments of quantization methods. However, the newly supported mxfp4 only allows groupSize = 32 and bits = 4, it'd be better to confine quantization modes with a full sum type, e.g.

enum QuantizationMode: Equatable {
  case affine(groupSize: Int, bits: Int)
  case mxfp4
}

If, in the future, MLX adds support to more quantization modes (e.g. mxfpN), mxfp4 can be converted into a convenience method to maintain source compatibility, i.e.

enum QuantizationMode: Equatable {
  case affine(groupSize: Int, bits: Int)
  case mxfpN(n: Int) 
}

extension QuantizationMode {
  static let mxfp4: Self = .mxfpN(n: 4)
}

mode == .mxfp4 // still works because of the Equatable conformance

It will be a source breaking change for all use sites of QuantizationMode though, but I believe the use of sum type in this case will make the API more extensible and fool-proof.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions