Merge pull request #3664 from ollama/mxyng/fix-padding-2
fix padding to only return padding
This commit is contained in:
commit
05e9424824
1 changed files with 13 additions and 8 deletions
21
llm/gguf.go
21
llm/gguf.go
|
@ -248,13 +248,17 @@ func (llm *gguf) Decode(rs io.ReadSeeker) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
padding := llm.padding(offset, int64(alignment))
|
padding := llm.padding(offset, int64(alignment))
|
||||||
if _, err := rs.Seek(padding-offset, io.SeekCurrent); err != nil {
|
if _, err := rs.Seek(padding, io.SeekCurrent); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tensor := range llm.tensors {
|
for _, tensor := range llm.tensors {
|
||||||
padded := (int64(tensor.size()) + int64(alignment) - 1) & ^(int64(alignment) - 1)
|
if _, err := rs.Seek(int64(tensor.size()), io.SeekCurrent); err != nil {
|
||||||
if _, err := rs.Seek(padded, io.SeekCurrent); err != nil {
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
padding := llm.padding(int64(tensor.size()), int64(alignment))
|
||||||
|
if _, err := rs.Seek(padding, io.SeekCurrent); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -623,8 +627,9 @@ func (llm *gguf) Encode(ws io.WriteSeeker, kv KV, tensors []Tensor) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
padding := llm.padding(offset, 32)
|
var alignment int64 = 32
|
||||||
if err := binary.Write(ws, llm.ByteOrder, bytes.Repeat([]byte{0}, int(padding-offset))); err != nil {
|
padding := llm.padding(offset, alignment)
|
||||||
|
if err := binary.Write(ws, llm.ByteOrder, bytes.Repeat([]byte{0}, int(padding))); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -638,8 +643,8 @@ func (llm *gguf) Encode(ws io.WriteSeeker, kv KV, tensors []Tensor) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
padding := llm.padding(offset, 32)
|
padding := llm.padding(offset, alignment)
|
||||||
if err := binary.Write(ws, llm.ByteOrder, bytes.Repeat([]byte{0}, int(padding-offset))); err != nil {
|
if err := binary.Write(ws, llm.ByteOrder, bytes.Repeat([]byte{0}, int(padding))); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -648,5 +653,5 @@ func (llm *gguf) Encode(ws io.WriteSeeker, kv KV, tensors []Tensor) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gguf) padding(offset, align int64) int64 {
|
func (gguf) padding(offset, align int64) int64 {
|
||||||
return (offset + align - 1) / align * align
|
return (align - offset%align) % align
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue