Skip to content

QuantizedLinear and QuantizedEmbedding displaying incorrect shapes #290

@AppAppWorks

Description

@AppAppWorks

The implementations of describeExtra of Linear and Embedding depend directly on weight for shape descriptions, resulting in incorrect shape descriptions for their quantized versions.

open class Embedding {
  public override func describeExtra(_ indent: Int) -> String {
     weight.shape.description
  }
}

open class Linear {
  open override func describeExtra(_ indent: Int) -> String {
    "(inputDimensions=\(weight.dim(1)), outputDimensions=\(weight.dim(0)), bias=\(bias == nil ? "false" : "true"))"
  }
}

For Linear and its subclasses, it can be easily fixed by:

open class Linear {
  open override func describeExtra(_ indent: Int) -> String {
    let (outputDimensions, inputDimensions) = self.shape
    return "(inputDimensions=\(inputDimensions), outputDimensions=\(outputDimensions), bias=\(bias == nil ? "false" : "true"))"
  }
}

For Embedding, we should introduce shape as in Linear. Besides, the access control modifier of describeExtra should be widened to open.

open class Embedding {
  open var shape: (Int, Int) {
    self.weight.shape2
  }

  open override func describeExtra(_ indent: Int) -> String {
    self.shape.description
  }
}

open class QuantizedEmbedding {
  open override var shape: (Int, Int) {
    let (embeddingCount, dimensions) = self.shape
    return (embeddingCount, dimensions * 32 / self.bits)
  }
}

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