fix parsing big endian gguf

This commit is contained in:
Michael Yang
2024-06-08 12:32:02 -07:00
parent cddc63381c
commit 620d5c569e
2 changed files with 19 additions and 9 deletions

View File

@@ -36,10 +36,23 @@ func (c *containerGGUF) Name() string {
}
func (c *containerGGUF) Decode(rs io.ReadSeeker) (model, error) {
if err := binary.Read(rs, c.ByteOrder, &c.Version); err != nil {
var version [4]byte
if err := binary.Read(rs, c.ByteOrder, &version); err != nil {
return nil, err
}
// if the lower 16 bits are 0, the byte order is probably wrong
if c.ByteOrder.Uint32(version[:])&1<<4 == 0 {
switch c.ByteOrder {
case binary.LittleEndian:
c.ByteOrder = binary.BigEndian
case binary.BigEndian:
c.ByteOrder = binary.LittleEndian
}
}
c.Version = c.ByteOrder.Uint32(version[:])
var err error
switch c.Version {
case 1: