Skip to content

Commit

Permalink
refactor: makefile
Browse files Browse the repository at this point in the history
Signed-off-by: thxCode <[email protected]>
  • Loading branch information
thxCode committed Jul 25, 2024
1 parent b72e7c6 commit 199f367
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 34 deletions.
41 changes: 23 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@ LINT_DIRTY ?= false
VERSION ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null | tr '[:upper:]' '[:lower:]' || echo "unknown")

deps:
@echo "+++ deps +++"
@echo "+++ $@ +++"

go mod tidy
go mod download
cd $(SRCDIR) && go mod tidy && go mod download
cd $(SRCDIR)/cmd/gguf-parser && go mod tidy && go mod download

cd "$(SRCDIR)/cmd/gguf-parser" && go mod tidy && go mod download

@echo "--- deps ---"
@echo "--- $@ ---"

generate:
@echo "+++ generate +++"
@echo "+++ $@ +++"

go generate $(SRCDIR)/...
cd $(SRCDIR) && go generate ./...
cd $(SRCDIR)/cmd/gguf-parser && go generate ./...

@echo "--- generate ---"
@echo "--- $@ ---"

lint:
@echo "+++ lint +++"
@echo "+++ $@ +++"

if [[ "$(LINT_DIRTY)" == "true" ]]; then \
if [[ -n $$(git status --porcelain) ]]; then \
Expand All @@ -41,32 +40,38 @@ lint:
[[ -f "$(SRCDIR)/.sbin/goimports-reviser" ]] || \
curl --retry 3 --retry-all-errors --retry-delay 3 -sSfL "https://github.com/incu6us/goimports-reviser/releases/download/v3.6.5/goimports-reviser_3.6.5_$(GOOS)_$(GOARCH).tar.gz" \
| tar -zxvf - --directory "$(SRCDIR)/.sbin" --no-same-owner --exclude ./LICENSE --exclude ./README.md && chmod +x "$(SRCDIR)/.sbin/goimports-reviser"
go list -f "{{.Dir}}" $(SRCDIR)/... | xargs -I {} find {} -maxdepth 1 -type f -name '*.go' ! -name 'gen.*' ! -name 'zz_generated.*' \
cd $(SRCDIR) && \
go list -f "{{.Dir}}" ./... | xargs -I {} find {} -maxdepth 1 -type f -name '*.go' ! -name 'gen.*' ! -name 'zz_generated.*' \
| xargs -I {} "$(SRCDIR)/.sbin/goimports-reviser" -use-cache -imports-order=std,general,company,project,blanked,dotted -output=file {}
cd $(SRCDIR)/cmd/gguf-parser && \
go list -f "{{.Dir}}" ./... | xargs -I {} find {} -maxdepth 1 -type f -name '*.go' ! -name 'gen.*' ! -name 'zz_generated.*' \
| xargs -I {} "$(SRCDIR)/.sbin/goimports-reviser" -use-cache -imports-order=std,general,company,project,blanked,dotted -output=file {}

[[ -f "$(SRCDIR)/.sbin/golangci-lint" ]] || \
curl --retry 3 --retry-all-errors --retry-delay 3 -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \
| sh -s -- -b "$(SRCDIR)/.sbin" "v1.59.0"
"$(SRCDIR)/.sbin/golangci-lint" run --fix $(SRCDIR)/...
cd $(SRCDIR) && \
"$(SRCDIR)/.sbin/golangci-lint" run --fix ./...
cd $(SRCDIR)/cmd/gguf-parser && \
"$(SRCDIR)/.sbin/golangci-lint" run --fix ./...

@echo "--- lint ---"
@echo "--- $@ ---"

test:
@echo "+++ test +++"
@echo "+++ $@ +++"

go test -v -failfast -race -cover -timeout=30m $(SRCDIR)/...

@echo "--- test ---"
@echo "--- $@ ---"

benchmark:
@echo "+++ benchmark +++"
@echo "+++ $@ +++"

go test -v -failfast -run="^Benchmark[A-Z]+" -bench=. -benchmem -timeout=30m $(SRCDIR)/...

@echo "--- benchmark ---"
@echo "--- $@ ---"

gguf-parser:
@echo "+++ gguf-parser +++"
[[ -d "$(SRCDIR)/.dist" ]] || mkdir -p "$(SRCDIR)/.dist"

cd "$(SRCDIR)/cmd/gguf-parser" && for os in darwin linux windows; do \
Expand Down
80 changes: 64 additions & 16 deletions cmd/gguf-parser/main.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package main

import (
"os"
"fmt"
"context"
"errors"
"fmt"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"sync"
"regexp"
"errors"
"path/filepath"

"github.com/urfave/cli/v2"
"github.com/olekukonko/tablewriter"

"github.com/thxcode/gguf-parser-go/util/anyx"
"github.com/thxcode/gguf-parser-go/util/json"
"github.com/thxcode/gguf-parser-go/util/signalx"
"github.com/urfave/cli/v2"

. "github.com/thxcode/gguf-parser-go"
. "github.com/thxcode/gguf-parser-go" // nolint: stylecheck
)

var Version = "v0.0.0"
Expand Down Expand Up @@ -817,7 +816,15 @@ func run(ctx context.Context) error {
if !skipModel {
tprint(
"MODEL",
[]string{"Name", "Arch", "Quantization", "Little Endian", "Size", "Parameters", "BPW"},
[]string{
"Name",
"Arch",
"Quantization",
"Little Endian",
"Size",
"Parameters",
"BPW",
},
nil,
[]string{
m.Name,
Expand All @@ -836,7 +843,16 @@ func run(ctx context.Context) error {
bd []string
)
if a.Architecture != "clip" {
hd = []string{"Max Context Len", "Embedding Len", "Embedding GQA", "Attention Head Cnt", "Layers", "Feed Forward Len", "Expert Cnt", "Vocabulary Len"}
hd = []string{
"Max Context Len",
"Embedding Len",
"Embedding GQA",
"Attention Head Cnt",
"Layers",
"Feed Forward Len",
"Expert Cnt",
"Vocabulary Len",
}
bd = []string{
sprintf(a.MaximumContextLength),
sprintf(a.EmbeddingLength),
Expand All @@ -848,7 +864,13 @@ func run(ctx context.Context) error {
sprintf(a.VocabularyLength),
}
} else {
hd = []string{"Embedding Len", "Layers", "Feed Forward Len", "Encoder", "LLaVA MultimodalProjector"}
hd = []string{
"Embedding Len",
"Layers",
"Feed Forward Len",
"Encoder",
"LLaVA MultimodalProjector",
}
bd = []string{
sprintf(a.EmbeddingLength),
sprintf(a.BlockCount),
Expand All @@ -867,7 +889,17 @@ func run(ctx context.Context) error {
if !skipTokenizer && t.Model != "" {
tprint(
"TOKENIZER",
[]string{"Model", "Tokens Size", "Tokens Len", "Added Tokens Len", "BOS Token", "EOS Token", "Unknown Token", "Separator Token", "Padding Token"},
[]string{
"Model",
"Tokens Size",
"Tokens Len",
"Added Tokens Len",
"BOS Token",
"EOS Token",
"Unknown Token",
"Separator Token",
"Padding Token",
},
nil,
[]string{
t.Model,
Expand All @@ -890,7 +922,17 @@ func run(ctx context.Context) error {
)
es := e.Summarize(mmap, platformRAM, platformVRAM)
if e.Architecture != "clip" {
hd = []string{"Arch", "Context Size", "Flash Attention", "MMap Support", "Offload Layers", "Full Offloaded", "UMA (RAM + VRAM)", "NonUMA RAM", "NonUMA VRAM"}
hd = []string{
"Arch",
"Context Size",
"Flash Attention",
"MMap Support",
"Offload Layers",
"Full Offloaded",
"UMA (RAM + VRAM)",
"NonUMA RAM",
"NonUMA VRAM",
}
mg = []int{0, 1, 2, 3, 5}

switch {
Expand Down Expand Up @@ -927,15 +969,21 @@ func run(ctx context.Context) error {
sprintf(es.ContextSize),
sprintf(es.FlashAttention),
sprintf(!es.NoMMap),
sprintf(tenary(es.Memory[i].FullOffloaded, sprintf("%d (%d + 1)", es.Memory[i].OffloadLayers, es.Memory[i].OffloadLayers-1), es.Memory[i].OffloadLayers)),
sprintf(tenary(es.Memory[i].FullOffloaded, sprintf("%d (%d + 1)",
es.Memory[i].OffloadLayers, es.Memory[i].OffloadLayers-1), es.Memory[i].OffloadLayers)),
sprintf(tenary(es.Memory[i].FullOffloaded, "Yes", "No")),
sprintf("%s + %s = %s", es.Memory[i].UMA.RAM, es.Memory[i].UMA.VRAM, es.Memory[i].UMA.RAM+es.Memory[i].UMA.VRAM),
sprintf(es.Memory[i].NonUMA.RAM),
sprintf(es.Memory[i].NonUMA.VRAM),
}
}
} else {
hd = []string{"Arch", "Offload Layers", "Full Offloaded", "(V)RAM"}
hd = []string{
"Arch",
"Offload Layers",
"Full Offloaded",
"(V)RAM",
}
bds = [][]string{
{
sprintf(es.Architecture),
Expand Down Expand Up @@ -986,7 +1034,7 @@ func tprint(title string, header []string, merges []int, body ...[]string) {
return []int{0}
}
r = make([]int, len(merges)+1)
r = append(r, 0)
r[0] = 0
for i := range merges {
r[i] = merges[i] + 1
}
Expand Down

0 comments on commit 199f367

Please sign in to comment.