Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
89d99001
Unverified
Commit
89d99001
authored
Jun 04, 2024
by
Michael Yang
Committed by
GitHub
Jun 04, 2024
Browse files
Merge pull request #4570 from ollama/mxyng/slices
lint some of the things
parents
4a048715
6297f856
Changes
54
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
93 additions
and
101 deletions
+93
-101
readline/term.go
readline/term.go
+3
-3
readline/term_bsd.go
readline/term_bsd.go
+4
-4
readline/term_linux.go
readline/term_linux.go
+4
-4
readline/term_windows.go
readline/term_windows.go
+3
-3
server/download.go
server/download.go
+1
-1
server/images.go
server/images.go
+4
-5
server/model.go
server/model.go
+0
-1
server/modelpath_test.go
server/modelpath_test.go
+3
-2
server/routes.go
server/routes.go
+2
-4
server/routes_test.go
server/routes_test.go
+31
-30
server/sched.go
server/sched.go
+3
-5
server/sched_test.go
server/sched_test.go
+28
-30
server/upload.go
server/upload.go
+4
-4
types/model/name_test.go
types/model/name_test.go
+3
-5
No files found.
readline/term.go
View file @
89d99001
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
type
Termios
syscall
.
Termios
type
Termios
syscall
.
Termios
func
SetRawMode
(
fd
int
)
(
*
Termios
,
error
)
{
func
SetRawMode
(
fd
u
int
ptr
)
(
*
Termios
,
error
)
{
termios
,
err
:=
getTermios
(
fd
)
termios
,
err
:=
getTermios
(
fd
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -25,13 +25,13 @@ func SetRawMode(fd int) (*Termios, error) {
...
@@ -25,13 +25,13 @@ func SetRawMode(fd int) (*Termios, error) {
return
termios
,
setTermios
(
fd
,
&
newTermios
)
return
termios
,
setTermios
(
fd
,
&
newTermios
)
}
}
func
UnsetRawMode
(
fd
int
,
termios
any
)
error
{
func
UnsetRawMode
(
fd
u
int
ptr
,
termios
any
)
error
{
t
:=
termios
.
(
*
Termios
)
t
:=
termios
.
(
*
Termios
)
return
setTermios
(
fd
,
t
)
return
setTermios
(
fd
,
t
)
}
}
// IsTerminal returns true if the given file descriptor is a terminal.
// IsTerminal returns true if the given file descriptor is a terminal.
func
IsTerminal
(
fd
int
)
bool
{
func
IsTerminal
(
fd
u
int
ptr
)
bool
{
_
,
err
:=
getTermios
(
fd
)
_
,
err
:=
getTermios
(
fd
)
return
err
==
nil
return
err
==
nil
}
}
readline/term_bsd.go
View file @
89d99001
...
@@ -7,17 +7,17 @@ import (
...
@@ -7,17 +7,17 @@ import (
"unsafe"
"unsafe"
)
)
func
getTermios
(
fd
int
)
(
*
Termios
,
error
)
{
func
getTermios
(
fd
u
int
ptr
)
(
*
Termios
,
error
)
{
termios
:=
new
(
Termios
)
termios
:=
new
(
Termios
)
_
,
_
,
err
:=
syscall
.
Syscall6
(
syscall
.
SYS_IOCTL
,
uintptr
(
fd
)
,
syscall
.
TIOCGETA
,
uintptr
(
unsafe
.
Pointer
(
termios
)),
0
,
0
,
0
)
_
,
_
,
err
:=
syscall
.
Syscall6
(
syscall
.
SYS_IOCTL
,
fd
,
syscall
.
TIOCGETA
,
uintptr
(
unsafe
.
Pointer
(
termios
)),
0
,
0
,
0
)
if
err
!=
0
{
if
err
!=
0
{
return
nil
,
err
return
nil
,
err
}
}
return
termios
,
nil
return
termios
,
nil
}
}
func
setTermios
(
fd
int
,
termios
*
Termios
)
error
{
func
setTermios
(
fd
u
int
ptr
,
termios
*
Termios
)
error
{
_
,
_
,
err
:=
syscall
.
Syscall6
(
syscall
.
SYS_IOCTL
,
uintptr
(
fd
)
,
syscall
.
TIOCSETA
,
uintptr
(
unsafe
.
Pointer
(
termios
)),
0
,
0
,
0
)
_
,
_
,
err
:=
syscall
.
Syscall6
(
syscall
.
SYS_IOCTL
,
fd
,
syscall
.
TIOCSETA
,
uintptr
(
unsafe
.
Pointer
(
termios
)),
0
,
0
,
0
)
if
err
!=
0
{
if
err
!=
0
{
return
err
return
err
}
}
...
...
readline/term_linux.go
View file @
89d99001
...
@@ -10,17 +10,17 @@ import (
...
@@ -10,17 +10,17 @@ import (
const
tcgets
=
0x5401
const
tcgets
=
0x5401
const
tcsets
=
0x5402
const
tcsets
=
0x5402
func
getTermios
(
fd
int
)
(
*
Termios
,
error
)
{
func
getTermios
(
fd
u
int
ptr
)
(
*
Termios
,
error
)
{
termios
:=
new
(
Termios
)
termios
:=
new
(
Termios
)
_
,
_
,
err
:=
syscall
.
Syscall6
(
syscall
.
SYS_IOCTL
,
uintptr
(
fd
)
,
tcgets
,
uintptr
(
unsafe
.
Pointer
(
termios
)),
0
,
0
,
0
)
_
,
_
,
err
:=
syscall
.
Syscall6
(
syscall
.
SYS_IOCTL
,
fd
,
tcgets
,
uintptr
(
unsafe
.
Pointer
(
termios
)),
0
,
0
,
0
)
if
err
!=
0
{
if
err
!=
0
{
return
nil
,
err
return
nil
,
err
}
}
return
termios
,
nil
return
termios
,
nil
}
}
func
setTermios
(
fd
int
,
termios
*
Termios
)
error
{
func
setTermios
(
fd
u
int
ptr
,
termios
*
Termios
)
error
{
_
,
_
,
err
:=
syscall
.
Syscall6
(
syscall
.
SYS_IOCTL
,
uintptr
(
fd
)
,
tcsets
,
uintptr
(
unsafe
.
Pointer
(
termios
)),
0
,
0
,
0
)
_
,
_
,
err
:=
syscall
.
Syscall6
(
syscall
.
SYS_IOCTL
,
fd
,
tcsets
,
uintptr
(
unsafe
.
Pointer
(
termios
)),
0
,
0
,
0
)
if
err
!=
0
{
if
err
!=
0
{
return
err
return
err
}
}
...
...
readline/term_windows.go
View file @
89d99001
...
@@ -9,13 +9,13 @@ type State struct {
...
@@ -9,13 +9,13 @@ type State struct {
}
}
// IsTerminal checks if the given file descriptor is associated with a terminal
// IsTerminal checks if the given file descriptor is associated with a terminal
func
IsTerminal
(
fd
int
)
bool
{
func
IsTerminal
(
fd
u
int
ptr
)
bool
{
var
st
uint32
var
st
uint32
err
:=
windows
.
GetConsoleMode
(
windows
.
Handle
(
fd
),
&
st
)
err
:=
windows
.
GetConsoleMode
(
windows
.
Handle
(
fd
),
&
st
)
return
err
==
nil
return
err
==
nil
}
}
func
SetRawMode
(
fd
int
)
(
*
State
,
error
)
{
func
SetRawMode
(
fd
u
int
ptr
)
(
*
State
,
error
)
{
var
st
uint32
var
st
uint32
if
err
:=
windows
.
GetConsoleMode
(
windows
.
Handle
(
fd
),
&
st
);
err
!=
nil
{
if
err
:=
windows
.
GetConsoleMode
(
windows
.
Handle
(
fd
),
&
st
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -32,7 +32,7 @@ func SetRawMode(fd int) (*State, error) {
...
@@ -32,7 +32,7 @@ func SetRawMode(fd int) (*State, error) {
return
&
State
{
st
},
nil
return
&
State
{
st
},
nil
}
}
func
UnsetRawMode
(
fd
int
,
state
any
)
error
{
func
UnsetRawMode
(
fd
u
int
ptr
,
state
any
)
error
{
s
:=
state
.
(
*
State
)
s
:=
state
.
(
*
State
)
return
windows
.
SetConsoleMode
(
windows
.
Handle
(
fd
),
s
.
mode
)
return
windows
.
SetConsoleMode
(
windows
.
Handle
(
fd
),
s
.
mode
)
}
}
server/download.go
View file @
89d99001
...
@@ -372,7 +372,7 @@ func downloadBlob(ctx context.Context, opts downloadOpts) error {
...
@@ -372,7 +372,7 @@ func downloadBlob(ctx context.Context, opts downloadOpts) error {
return
err
return
err
}
}
//
nolint:
contextcheck
//nolint:contextcheck
go
download
.
Run
(
context
.
Background
(),
requestURL
,
opts
.
regOpts
)
go
download
.
Run
(
context
.
Background
(),
requestURL
,
opts
.
regOpts
)
}
}
...
...
server/images.go
View file @
89d99001
...
@@ -18,17 +18,16 @@ import (
...
@@ -18,17 +18,16 @@ import (
"os"
"os"
"path/filepath"
"path/filepath"
"runtime"
"runtime"
"slices"
"strconv"
"strconv"
"strings"
"strings"
"golang.org/x/exp/slices"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/auth"
"github.com/ollama/ollama/auth"
"github.com/ollama/ollama/envconfig"
"github.com/ollama/ollama/format"
"github.com/ollama/ollama/format"
"github.com/ollama/ollama/llm"
"github.com/ollama/ollama/llm"
"github.com/ollama/ollama/parser"
"github.com/ollama/ollama/parser"
"github.com/ollama/ollama/envconfig"
"github.com/ollama/ollama/types/errtypes"
"github.com/ollama/ollama/types/errtypes"
"github.com/ollama/ollama/types/model"
"github.com/ollama/ollama/types/model"
"github.com/ollama/ollama/version"
"github.com/ollama/ollama/version"
...
@@ -662,7 +661,7 @@ func deleteUnusedLayers(skipModelPath *ModelPath, deleteMap map[string]struct{})
...
@@ -662,7 +661,7 @@ func deleteUnusedLayers(skipModelPath *ModelPath, deleteMap map[string]struct{})
// save (i.e. delete from the deleteMap) any files used in other manifests
// save (i.e. delete from the deleteMap) any files used in other manifests
manifest
,
_
,
err
:=
GetManifest
(
fmp
)
manifest
,
_
,
err
:=
GetManifest
(
fmp
)
if
err
!=
nil
{
if
err
!=
nil
{
//
nolint:
nilerr
//nolint:nilerr
return
nil
return
nil
}
}
...
@@ -988,7 +987,7 @@ func getTokenSubject(token string) string {
...
@@ -988,7 +987,7 @@ func getTokenSubject(token string) string {
func
makeRequestWithRetry
(
ctx
context
.
Context
,
method
string
,
requestURL
*
url
.
URL
,
headers
http
.
Header
,
body
io
.
ReadSeeker
,
regOpts
*
registryOptions
)
(
*
http
.
Response
,
error
)
{
func
makeRequestWithRetry
(
ctx
context
.
Context
,
method
string
,
requestURL
*
url
.
URL
,
headers
http
.
Header
,
body
io
.
ReadSeeker
,
regOpts
*
registryOptions
)
(
*
http
.
Response
,
error
)
{
anonymous
:=
true
// access will default to anonymous if no user is found associated with the public key
anonymous
:=
true
// access will default to anonymous if no user is found associated with the public key
for
i
:=
0
;
i
<
2
;
i
++
{
for
range
2
{
resp
,
err
:=
makeRequest
(
ctx
,
method
,
requestURL
,
headers
,
body
,
regOpts
)
resp
,
err
:=
makeRequest
(
ctx
,
method
,
requestURL
,
headers
,
body
,
regOpts
)
if
err
!=
nil
{
if
err
!=
nil
{
if
!
errors
.
Is
(
err
,
context
.
Canceled
)
{
if
!
errors
.
Is
(
err
,
context
.
Canceled
)
{
...
...
server/model.go
View file @
89d99001
...
@@ -72,7 +72,6 @@ func parseFromModel(ctx context.Context, name model.Name, fn func(api.ProgressRe
...
@@ -72,7 +72,6 @@ func parseFromModel(ctx context.Context, name model.Name, fn func(api.ProgressRe
default
:
default
:
layers
=
append
(
layers
,
&
layerWithGGML
{
layer
,
nil
})
layers
=
append
(
layers
,
&
layerWithGGML
{
layer
,
nil
})
}
}
}
}
return
layers
,
nil
return
layers
,
nil
...
...
server/modelpath_test.go
View file @
89d99001
...
@@ -6,12 +6,13 @@ import (
...
@@ -6,12 +6,13 @@ import (
"testing"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
)
func
TestGetBlobsPath
(
t
*
testing
.
T
)
{
func
TestGetBlobsPath
(
t
*
testing
.
T
)
{
// GetBlobsPath expects an actual directory to exist
// GetBlobsPath expects an actual directory to exist
dir
,
err
:=
os
.
MkdirTemp
(
""
,
"ollama-test"
)
dir
,
err
:=
os
.
MkdirTemp
(
""
,
"ollama-test"
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
defer
os
.
RemoveAll
(
dir
)
defer
os
.
RemoveAll
(
dir
)
tests
:=
[]
struct
{
tests
:=
[]
struct
{
...
@@ -63,7 +64,7 @@ func TestGetBlobsPath(t *testing.T) {
...
@@ -63,7 +64,7 @@ func TestGetBlobsPath(t *testing.T) {
got
,
err
:=
GetBlobsPath
(
tc
.
digest
)
got
,
err
:=
GetBlobsPath
(
tc
.
digest
)
assert
.
ErrorIs
(
t
,
tc
.
err
,
err
,
tc
.
name
)
require
.
ErrorIs
(
t
,
tc
.
err
,
err
,
tc
.
name
)
assert
.
Equal
(
t
,
tc
.
expected
,
got
,
tc
.
name
)
assert
.
Equal
(
t
,
tc
.
expected
,
got
,
tc
.
name
)
})
})
}
}
...
...
server/routes.go
View file @
89d99001
...
@@ -16,6 +16,7 @@ import (
...
@@ -16,6 +16,7 @@ import (
"os"
"os"
"os/signal"
"os/signal"
"path/filepath"
"path/filepath"
"slices"
"strconv"
"strconv"
"strings"
"strings"
"syscall"
"syscall"
...
@@ -23,7 +24,6 @@ import (
...
@@ -23,7 +24,6 @@ import (
"github.com/gin-contrib/cors"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"golang.org/x/exp/slices"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/envconfig"
"github.com/ollama/ollama/envconfig"
...
@@ -77,7 +77,6 @@ func isSupportedImageType(image []byte) bool {
...
@@ -77,7 +77,6 @@ func isSupportedImageType(image []byte) bool {
}
}
func
(
s
*
Server
)
GenerateHandler
(
c
*
gin
.
Context
)
{
func
(
s
*
Server
)
GenerateHandler
(
c
*
gin
.
Context
)
{
checkpointStart
:=
time
.
Now
()
checkpointStart
:=
time
.
Now
()
var
req
api
.
GenerateRequest
var
req
api
.
GenerateRequest
err
:=
c
.
ShouldBindJSON
(
&
req
)
err
:=
c
.
ShouldBindJSON
(
&
req
)
...
@@ -942,7 +941,7 @@ func allowedHostsMiddleware(addr net.Addr) gin.HandlerFunc {
...
@@ -942,7 +941,7 @@ func allowedHostsMiddleware(addr net.Addr) gin.HandlerFunc {
}
}
if
allowedHost
(
host
)
{
if
allowedHost
(
host
)
{
if
c
.
Request
.
Method
==
"OPTIONS"
{
if
c
.
Request
.
Method
==
http
.
MethodOptions
{
c
.
AbortWithStatus
(
http
.
StatusNoContent
)
c
.
AbortWithStatus
(
http
.
StatusNoContent
)
return
return
}
}
...
@@ -1306,7 +1305,6 @@ func (s *Server) ChatHandler(c *gin.Context) {
...
@@ -1306,7 +1305,6 @@ func (s *Server) ChatHandler(c *gin.Context) {
defer
close
(
ch
)
defer
close
(
ch
)
fn
:=
func
(
r
llm
.
CompletionResponse
)
{
fn
:=
func
(
r
llm
.
CompletionResponse
)
{
resp
:=
api
.
ChatResponse
{
resp
:=
api
.
ChatResponse
{
Model
:
req
.
Model
,
Model
:
req
.
Model
,
CreatedAt
:
time
.
Now
()
.
UTC
(),
CreatedAt
:
time
.
Now
()
.
UTC
(),
...
...
server/routes_test.go
View file @
89d99001
...
@@ -15,6 +15,7 @@ import (
...
@@ -15,6 +15,7 @@ import (
"testing"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/parser"
"github.com/ollama/ollama/parser"
...
@@ -25,20 +26,20 @@ func createTestFile(t *testing.T, name string) string {
...
@@ -25,20 +26,20 @@ func createTestFile(t *testing.T, name string) string {
t
.
Helper
()
t
.
Helper
()
f
,
err
:=
os
.
CreateTemp
(
t
.
TempDir
(),
name
)
f
,
err
:=
os
.
CreateTemp
(
t
.
TempDir
(),
name
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
defer
f
.
Close
()
defer
f
.
Close
()
err
=
binary
.
Write
(
f
,
binary
.
LittleEndian
,
[]
byte
(
"GGUF"
))
err
=
binary
.
Write
(
f
,
binary
.
LittleEndian
,
[]
byte
(
"GGUF"
))
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
err
=
binary
.
Write
(
f
,
binary
.
LittleEndian
,
uint32
(
3
))
err
=
binary
.
Write
(
f
,
binary
.
LittleEndian
,
uint32
(
3
))
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
err
=
binary
.
Write
(
f
,
binary
.
LittleEndian
,
uint64
(
0
))
err
=
binary
.
Write
(
f
,
binary
.
LittleEndian
,
uint64
(
0
))
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
err
=
binary
.
Write
(
f
,
binary
.
LittleEndian
,
uint64
(
0
))
err
=
binary
.
Write
(
f
,
binary
.
LittleEndian
,
uint64
(
0
))
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
return
f
.
Name
()
return
f
.
Name
()
}
}
...
@@ -57,12 +58,12 @@ func Test_Routes(t *testing.T) {
...
@@ -57,12 +58,12 @@ func Test_Routes(t *testing.T) {
r
:=
strings
.
NewReader
(
fmt
.
Sprintf
(
"FROM %s
\n
PARAMETER seed 42
\n
PARAMETER top_p 0.9
\n
PARAMETER stop foo
\n
PARAMETER stop bar"
,
fname
))
r
:=
strings
.
NewReader
(
fmt
.
Sprintf
(
"FROM %s
\n
PARAMETER seed 42
\n
PARAMETER top_p 0.9
\n
PARAMETER stop foo
\n
PARAMETER stop bar"
,
fname
))
modelfile
,
err
:=
parser
.
ParseFile
(
r
)
modelfile
,
err
:=
parser
.
ParseFile
(
r
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
fn
:=
func
(
resp
api
.
ProgressResponse
)
{
fn
:=
func
(
resp
api
.
ProgressResponse
)
{
t
.
Logf
(
"Status: %s"
,
resp
.
Status
)
t
.
Logf
(
"Status: %s"
,
resp
.
Status
)
}
}
err
=
CreateModel
(
context
.
TODO
(),
name
,
""
,
""
,
modelfile
,
fn
)
err
=
CreateModel
(
context
.
TODO
(),
name
,
""
,
""
,
modelfile
,
fn
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
}
}
testCases
:=
[]
testCase
{
testCases
:=
[]
testCase
{
...
@@ -74,9 +75,9 @@ func Test_Routes(t *testing.T) {
...
@@ -74,9 +75,9 @@ func Test_Routes(t *testing.T) {
},
},
Expected
:
func
(
t
*
testing
.
T
,
resp
*
http
.
Response
)
{
Expected
:
func
(
t
*
testing
.
T
,
resp
*
http
.
Response
)
{
contentType
:=
resp
.
Header
.
Get
(
"Content-Type"
)
contentType
:=
resp
.
Header
.
Get
(
"Content-Type"
)
assert
.
Equal
(
t
,
contentType
,
"application/json; charset=utf-8"
)
assert
.
Equal
(
t
,
"application/json; charset=utf-8"
,
contentType
)
body
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
body
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
fmt
.
Sprintf
(
`{"version":"%s"}`
,
version
.
Version
),
string
(
body
))
assert
.
Equal
(
t
,
fmt
.
Sprintf
(
`{"version":"%s"}`
,
version
.
Version
),
string
(
body
))
},
},
},
},
...
@@ -86,17 +87,17 @@ func Test_Routes(t *testing.T) {
...
@@ -86,17 +87,17 @@ func Test_Routes(t *testing.T) {
Path
:
"/api/tags"
,
Path
:
"/api/tags"
,
Expected
:
func
(
t
*
testing
.
T
,
resp
*
http
.
Response
)
{
Expected
:
func
(
t
*
testing
.
T
,
resp
*
http
.
Response
)
{
contentType
:=
resp
.
Header
.
Get
(
"Content-Type"
)
contentType
:=
resp
.
Header
.
Get
(
"Content-Type"
)
assert
.
Equal
(
t
,
contentType
,
"application/json; charset=utf-8"
)
assert
.
Equal
(
t
,
"application/json; charset=utf-8"
,
contentType
)
body
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
body
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
var
modelList
api
.
ListResponse
var
modelList
api
.
ListResponse
err
=
json
.
Unmarshal
(
body
,
&
modelList
)
err
=
json
.
Unmarshal
(
body
,
&
modelList
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
modelList
.
Models
)
assert
.
NotNil
(
t
,
modelList
.
Models
)
assert
.
E
qual
(
t
,
0
,
len
(
modelList
.
Models
))
assert
.
E
mpty
(
t
,
len
(
modelList
.
Models
))
},
},
},
},
{
{
...
@@ -108,16 +109,16 @@ func Test_Routes(t *testing.T) {
...
@@ -108,16 +109,16 @@ func Test_Routes(t *testing.T) {
},
},
Expected
:
func
(
t
*
testing
.
T
,
resp
*
http
.
Response
)
{
Expected
:
func
(
t
*
testing
.
T
,
resp
*
http
.
Response
)
{
contentType
:=
resp
.
Header
.
Get
(
"Content-Type"
)
contentType
:=
resp
.
Header
.
Get
(
"Content-Type"
)
assert
.
Equal
(
t
,
contentType
,
"application/json; charset=utf-8"
)
assert
.
Equal
(
t
,
"application/json; charset=utf-8"
,
contentType
)
body
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
body
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
var
modelList
api
.
ListResponse
var
modelList
api
.
ListResponse
err
=
json
.
Unmarshal
(
body
,
&
modelList
)
err
=
json
.
Unmarshal
(
body
,
&
modelList
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
1
,
len
(
modelList
.
Models
)
)
assert
.
Len
(
t
,
modelList
.
Models
,
1
)
assert
.
Equal
(
t
,
modelList
.
Models
[
0
]
.
Name
,
"test-model:latest"
)
assert
.
Equal
(
t
,
"test-model:latest"
,
modelList
.
Models
[
0
]
.
Name
)
},
},
},
},
{
{
...
@@ -134,7 +135,7 @@ func Test_Routes(t *testing.T) {
...
@@ -134,7 +135,7 @@ func Test_Routes(t *testing.T) {
Stream
:
&
stream
,
Stream
:
&
stream
,
}
}
jsonData
,
err
:=
json
.
Marshal
(
createReq
)
jsonData
,
err
:=
json
.
Marshal
(
createReq
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
req
.
Body
=
io
.
NopCloser
(
bytes
.
NewReader
(
jsonData
))
req
.
Body
=
io
.
NopCloser
(
bytes
.
NewReader
(
jsonData
))
},
},
...
@@ -142,11 +143,11 @@ func Test_Routes(t *testing.T) {
...
@@ -142,11 +143,11 @@ func Test_Routes(t *testing.T) {
contentType
:=
resp
.
Header
.
Get
(
"Content-Type"
)
contentType
:=
resp
.
Header
.
Get
(
"Content-Type"
)
assert
.
Equal
(
t
,
"application/json"
,
contentType
)
assert
.
Equal
(
t
,
"application/json"
,
contentType
)
_
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
_
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
resp
.
StatusCode
,
200
)
assert
.
Equal
(
t
,
200
,
resp
.
StatusCode
)
model
,
err
:=
GetModel
(
"t-bone"
)
model
,
err
:=
GetModel
(
"t-bone"
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
"t-bone:latest"
,
model
.
ShortName
)
assert
.
Equal
(
t
,
"t-bone:latest"
,
model
.
ShortName
)
},
},
},
},
...
@@ -161,13 +162,13 @@ func Test_Routes(t *testing.T) {
...
@@ -161,13 +162,13 @@ func Test_Routes(t *testing.T) {
Destination
:
"beefsteak"
,
Destination
:
"beefsteak"
,
}
}
jsonData
,
err
:=
json
.
Marshal
(
copyReq
)
jsonData
,
err
:=
json
.
Marshal
(
copyReq
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
req
.
Body
=
io
.
NopCloser
(
bytes
.
NewReader
(
jsonData
))
req
.
Body
=
io
.
NopCloser
(
bytes
.
NewReader
(
jsonData
))
},
},
Expected
:
func
(
t
*
testing
.
T
,
resp
*
http
.
Response
)
{
Expected
:
func
(
t
*
testing
.
T
,
resp
*
http
.
Response
)
{
model
,
err
:=
GetModel
(
"beefsteak"
)
model
,
err
:=
GetModel
(
"beefsteak"
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
"beefsteak:latest"
,
model
.
ShortName
)
assert
.
Equal
(
t
,
"beefsteak:latest"
,
model
.
ShortName
)
},
},
},
},
...
@@ -179,18 +180,18 @@ func Test_Routes(t *testing.T) {
...
@@ -179,18 +180,18 @@ func Test_Routes(t *testing.T) {
createTestModel
(
t
,
"show-model"
)
createTestModel
(
t
,
"show-model"
)
showReq
:=
api
.
ShowRequest
{
Model
:
"show-model"
}
showReq
:=
api
.
ShowRequest
{
Model
:
"show-model"
}
jsonData
,
err
:=
json
.
Marshal
(
showReq
)
jsonData
,
err
:=
json
.
Marshal
(
showReq
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
req
.
Body
=
io
.
NopCloser
(
bytes
.
NewReader
(
jsonData
))
req
.
Body
=
io
.
NopCloser
(
bytes
.
NewReader
(
jsonData
))
},
},
Expected
:
func
(
t
*
testing
.
T
,
resp
*
http
.
Response
)
{
Expected
:
func
(
t
*
testing
.
T
,
resp
*
http
.
Response
)
{
contentType
:=
resp
.
Header
.
Get
(
"Content-Type"
)
contentType
:=
resp
.
Header
.
Get
(
"Content-Type"
)
assert
.
Equal
(
t
,
contentType
,
"application/json; charset=utf-8"
)
assert
.
Equal
(
t
,
"application/json; charset=utf-8"
,
contentType
)
body
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
body
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
var
showResp
api
.
ShowResponse
var
showResp
api
.
ShowResponse
err
=
json
.
Unmarshal
(
body
,
&
showResp
)
err
=
json
.
Unmarshal
(
body
,
&
showResp
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
var
params
[]
string
var
params
[]
string
paramsSplit
:=
strings
.
Split
(
showResp
.
Parameters
,
"
\n
"
)
paramsSplit
:=
strings
.
Split
(
showResp
.
Parameters
,
"
\n
"
)
...
@@ -221,14 +222,14 @@ func Test_Routes(t *testing.T) {
...
@@ -221,14 +222,14 @@ func Test_Routes(t *testing.T) {
t
.
Run
(
tc
.
Name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tc
.
Name
,
func
(
t
*
testing
.
T
)
{
u
:=
httpSrv
.
URL
+
tc
.
Path
u
:=
httpSrv
.
URL
+
tc
.
Path
req
,
err
:=
http
.
NewRequestWithContext
(
context
.
TODO
(),
tc
.
Method
,
u
,
nil
)
req
,
err
:=
http
.
NewRequestWithContext
(
context
.
TODO
(),
tc
.
Method
,
u
,
nil
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
if
tc
.
Setup
!=
nil
{
if
tc
.
Setup
!=
nil
{
tc
.
Setup
(
t
,
req
)
tc
.
Setup
(
t
,
req
)
}
}
resp
,
err
:=
httpSrv
.
Client
()
.
Do
(
req
)
resp
,
err
:=
httpSrv
.
Client
()
.
Do
(
req
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
defer
resp
.
Body
.
Close
()
defer
resp
.
Body
.
Close
()
if
tc
.
Expected
!=
nil
{
if
tc
.
Expected
!=
nil
{
...
...
server/sched.go
View file @
89d99001
...
@@ -7,17 +7,17 @@ import (
...
@@ -7,17 +7,17 @@ import (
"log/slog"
"log/slog"
"reflect"
"reflect"
"runtime"
"runtime"
"slices"
"sort"
"sort"
"strings"
"strings"
"sync"
"sync"
"time"
"time"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/envconfig"
"github.com/ollama/ollama/format"
"github.com/ollama/ollama/format"
"github.com/ollama/ollama/gpu"
"github.com/ollama/ollama/gpu"
"github.com/ollama/ollama/llm"
"github.com/ollama/ollama/llm"
"github.com/ollama/ollama/envconfig"
"golang.org/x/exp/slices"
)
)
type
LlmRequest
struct
{
type
LlmRequest
struct
{
...
@@ -66,7 +66,7 @@ func (s *Scheduler) GetRunner(c context.Context, model *Model, opts api.Options,
...
@@ -66,7 +66,7 @@ func (s *Scheduler) GetRunner(c context.Context, model *Model, opts api.Options,
opts
.
NumCtx
=
4
opts
.
NumCtx
=
4
}
}
opts
.
NumCtx
=
opts
.
NumCtx
*
envconfig
.
NumParallel
opts
.
NumCtx
*
=
envconfig
.
NumParallel
req
:=
&
LlmRequest
{
req
:=
&
LlmRequest
{
ctx
:
c
,
ctx
:
c
,
...
@@ -370,7 +370,6 @@ func (s *Scheduler) updateFreeSpace(allGpus gpu.GpuInfoList) {
...
@@ -370,7 +370,6 @@ func (s *Scheduler) updateFreeSpace(allGpus gpu.GpuInfoList) {
r
.
refMu
.
Lock
()
r
.
refMu
.
Lock
()
gpuIDs
:=
make
([]
string
,
0
,
len
(
r
.
gpus
))
gpuIDs
:=
make
([]
string
,
0
,
len
(
r
.
gpus
))
if
r
.
llama
!=
nil
{
if
r
.
llama
!=
nil
{
// TODO this should be broken down by GPU instead of assuming uniform spread
// TODO this should be broken down by GPU instead of assuming uniform spread
estimatedVRAMPerGPU
:=
r
.
llama
.
EstimatedVRAM
()
/
uint64
(
len
(
r
.
gpus
))
estimatedVRAMPerGPU
:=
r
.
llama
.
EstimatedVRAM
()
/
uint64
(
len
(
r
.
gpus
))
for
_
,
gpu
:=
range
r
.
gpus
{
for
_
,
gpu
:=
range
r
.
gpus
{
...
@@ -529,7 +528,6 @@ func (runner *runnerRef) waitForVRAMRecovery() chan interface{} {
...
@@ -529,7 +528,6 @@ func (runner *runnerRef) waitForVRAMRecovery() chan interface{} {
}
}
}()
}()
return
finished
return
finished
}
}
type
ByDuration
[]
*
runnerRef
type
ByDuration
[]
*
runnerRef
...
...
server/sched_test.go
View file @
89d99001
...
@@ -12,11 +12,10 @@ import (
...
@@ -12,11 +12,10 @@ import (
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/app/lifecycle"
"github.com/ollama/ollama/app/lifecycle"
"github.com/ollama/ollama/envconfig"
"github.com/ollama/ollama/format"
"github.com/ollama/ollama/format"
"github.com/ollama/ollama/gpu"
"github.com/ollama/ollama/gpu"
"github.com/ollama/ollama/llm"
"github.com/ollama/ollama/llm"
"github.com/ollama/ollama/envconfig"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
)
)
...
@@ -53,10 +52,10 @@ func TestLoad(t *testing.T) {
...
@@ -53,10 +52,10 @@ func TestLoad(t *testing.T) {
}
}
gpus
:=
gpu
.
GpuInfoList
{}
gpus
:=
gpu
.
GpuInfoList
{}
s
.
load
(
req
,
ggml
,
gpus
)
s
.
load
(
req
,
ggml
,
gpus
)
require
.
Len
(
t
,
req
.
successCh
,
0
)
require
.
Empty
(
t
,
req
.
successCh
)
require
.
Len
(
t
,
req
.
errCh
,
1
)
require
.
Len
(
t
,
req
.
errCh
,
1
)
s
.
loadedMu
.
Lock
()
s
.
loadedMu
.
Lock
()
require
.
Len
(
t
,
s
.
loaded
,
0
)
require
.
Empty
(
t
,
s
.
loaded
)
s
.
loadedMu
.
Unlock
()
s
.
loadedMu
.
Unlock
()
err
:=
<-
req
.
errCh
err
:=
<-
req
.
errCh
require
.
Contains
(
t
,
err
.
Error
(),
"this model may be incompatible"
)
require
.
Contains
(
t
,
err
.
Error
(),
"this model may be incompatible"
)
...
@@ -113,7 +112,7 @@ func newScenario(t *testing.T, ctx context.Context, modelName string, estimatedV
...
@@ -113,7 +112,7 @@ func newScenario(t *testing.T, ctx context.Context, modelName string, estimatedV
t
.
Helper
()
t
.
Helper
()
f
,
err
:=
os
.
CreateTemp
(
t
.
TempDir
(),
modelName
)
f
,
err
:=
os
.
CreateTemp
(
t
.
TempDir
(),
modelName
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
defer
f
.
Close
()
defer
f
.
Close
()
gguf
:=
llm
.
NewGGUFV3
(
binary
.
LittleEndian
)
gguf
:=
llm
.
NewGGUFV3
(
binary
.
LittleEndian
)
...
@@ -131,7 +130,7 @@ func newScenario(t *testing.T, ctx context.Context, modelName string, estimatedV
...
@@ -131,7 +130,7 @@ func newScenario(t *testing.T, ctx context.Context, modelName string, estimatedV
},
[]
llm
.
Tensor
{
},
[]
llm
.
Tensor
{
{
Name
:
"blk.0.attn.weight"
,
Kind
:
uint32
(
0
),
Offset
:
uint64
(
0
),
Shape
:
[]
uint64
{
1
,
1
,
1
,
1
},
WriterTo
:
&
bytes
.
Reader
{}},
{
Name
:
"blk.0.attn.weight"
,
Kind
:
uint32
(
0
),
Offset
:
uint64
(
0
),
Shape
:
[]
uint64
{
1
,
1
,
1
,
1
},
WriterTo
:
&
bytes
.
Reader
{}},
})
})
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
fname
:=
f
.
Name
()
fname
:=
f
.
Name
()
model
:=
&
Model
{
Name
:
modelName
,
ModelPath
:
fname
}
model
:=
&
Model
{
Name
:
modelName
,
ModelPath
:
fname
}
...
@@ -190,8 +189,8 @@ func TestRequests(t *testing.T) {
...
@@ -190,8 +189,8 @@ func TestRequests(t *testing.T) {
select
{
select
{
case
resp
:=
<-
scenario1a
.
req
.
successCh
:
case
resp
:=
<-
scenario1a
.
req
.
successCh
:
require
.
Equal
(
t
,
resp
.
llama
,
scenario1a
.
srv
)
require
.
Equal
(
t
,
resp
.
llama
,
scenario1a
.
srv
)
require
.
Len
(
t
,
s
.
pendingReqCh
,
0
)
require
.
Empty
(
t
,
s
.
pendingReqCh
)
require
.
Len
(
t
,
scenario1a
.
req
.
errCh
,
0
)
require
.
Empty
(
t
,
scenario1a
.
req
.
errCh
)
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
t
.
Errorf
(
"timeout"
)
t
.
Errorf
(
"timeout"
)
}
}
...
@@ -203,8 +202,8 @@ func TestRequests(t *testing.T) {
...
@@ -203,8 +202,8 @@ func TestRequests(t *testing.T) {
select
{
select
{
case
resp
:=
<-
scenario1b
.
req
.
successCh
:
case
resp
:=
<-
scenario1b
.
req
.
successCh
:
require
.
Equal
(
t
,
resp
.
llama
,
scenario1a
.
srv
)
require
.
Equal
(
t
,
resp
.
llama
,
scenario1a
.
srv
)
require
.
Len
(
t
,
s
.
pendingReqCh
,
0
)
require
.
Empty
(
t
,
s
.
pendingReqCh
)
require
.
Len
(
t
,
scenario1b
.
req
.
errCh
,
0
)
require
.
Empty
(
t
,
scenario1b
.
req
.
errCh
)
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
t
.
Errorf
(
"timeout"
)
t
.
Errorf
(
"timeout"
)
}
}
...
@@ -221,8 +220,8 @@ func TestRequests(t *testing.T) {
...
@@ -221,8 +220,8 @@ func TestRequests(t *testing.T) {
select
{
select
{
case
resp
:=
<-
scenario2a
.
req
.
successCh
:
case
resp
:=
<-
scenario2a
.
req
.
successCh
:
require
.
Equal
(
t
,
resp
.
llama
,
scenario2a
.
srv
)
require
.
Equal
(
t
,
resp
.
llama
,
scenario2a
.
srv
)
require
.
Len
(
t
,
s
.
pendingReqCh
,
0
)
require
.
Empty
(
t
,
s
.
pendingReqCh
)
require
.
Len
(
t
,
scenario2a
.
req
.
errCh
,
0
)
require
.
Empty
(
t
,
scenario2a
.
req
.
errCh
)
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
t
.
Errorf
(
"timeout"
)
t
.
Errorf
(
"timeout"
)
}
}
...
@@ -237,8 +236,8 @@ func TestRequests(t *testing.T) {
...
@@ -237,8 +236,8 @@ func TestRequests(t *testing.T) {
select
{
select
{
case
resp
:=
<-
scenario3a
.
req
.
successCh
:
case
resp
:=
<-
scenario3a
.
req
.
successCh
:
require
.
Equal
(
t
,
resp
.
llama
,
scenario3a
.
srv
)
require
.
Equal
(
t
,
resp
.
llama
,
scenario3a
.
srv
)
require
.
Len
(
t
,
s
.
pendingReqCh
,
0
)
require
.
Empty
(
t
,
s
.
pendingReqCh
)
require
.
Len
(
t
,
scenario3a
.
req
.
errCh
,
0
)
require
.
Empty
(
t
,
scenario3a
.
req
.
errCh
)
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
t
.
Errorf
(
"timeout"
)
t
.
Errorf
(
"timeout"
)
}
}
...
@@ -253,8 +252,8 @@ func TestRequests(t *testing.T) {
...
@@ -253,8 +252,8 @@ func TestRequests(t *testing.T) {
select
{
select
{
case
resp
:=
<-
scenario3b
.
req
.
successCh
:
case
resp
:=
<-
scenario3b
.
req
.
successCh
:
require
.
Equal
(
t
,
resp
.
llama
,
scenario3b
.
srv
)
require
.
Equal
(
t
,
resp
.
llama
,
scenario3b
.
srv
)
require
.
Len
(
t
,
s
.
pendingReqCh
,
0
)
require
.
Empty
(
t
,
s
.
pendingReqCh
)
require
.
Len
(
t
,
scenario3b
.
req
.
errCh
,
0
)
require
.
Empty
(
t
,
scenario3b
.
req
.
errCh
)
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
t
.
Errorf
(
"timeout"
)
t
.
Errorf
(
"timeout"
)
}
}
...
@@ -269,8 +268,8 @@ func TestRequests(t *testing.T) {
...
@@ -269,8 +268,8 @@ func TestRequests(t *testing.T) {
select
{
select
{
case
resp
:=
<-
scenario3c
.
req
.
successCh
:
case
resp
:=
<-
scenario3c
.
req
.
successCh
:
require
.
Equal
(
t
,
resp
.
llama
,
scenario3c
.
srv
)
require
.
Equal
(
t
,
resp
.
llama
,
scenario3c
.
srv
)
require
.
Len
(
t
,
s
.
pendingReqCh
,
0
)
require
.
Empty
(
t
,
s
.
pendingReqCh
)
require
.
Len
(
t
,
scenario3c
.
req
.
errCh
,
0
)
require
.
Empty
(
t
,
scenario3c
.
req
.
errCh
)
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
t
.
Errorf
(
"timeout"
)
t
.
Errorf
(
"timeout"
)
}
}
...
@@ -296,8 +295,8 @@ func TestRequests(t *testing.T) {
...
@@ -296,8 +295,8 @@ func TestRequests(t *testing.T) {
select
{
select
{
case
resp
:=
<-
scenario3d
.
req
.
successCh
:
case
resp
:=
<-
scenario3d
.
req
.
successCh
:
require
.
Equal
(
t
,
resp
.
llama
,
scenario3d
.
srv
)
require
.
Equal
(
t
,
resp
.
llama
,
scenario3d
.
srv
)
require
.
Len
(
t
,
s
.
pendingReqCh
,
0
)
require
.
Empty
(
t
,
s
.
pendingReqCh
)
require
.
Len
(
t
,
scenario3d
.
req
.
errCh
,
0
)
require
.
Empty
(
t
,
scenario3d
.
req
.
errCh
)
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
t
.
Errorf
(
"timeout"
)
t
.
Errorf
(
"timeout"
)
}
}
...
@@ -332,7 +331,7 @@ func TestGetRunner(t *testing.T) {
...
@@ -332,7 +331,7 @@ func TestGetRunner(t *testing.T) {
slog
.
Info
(
"scenario1b"
)
slog
.
Info
(
"scenario1b"
)
successCh1b
,
errCh1b
:=
s
.
GetRunner
(
scenario1b
.
ctx
,
scenario1b
.
req
.
model
,
scenario1b
.
req
.
opts
,
scenario1b
.
req
.
sessionDuration
)
successCh1b
,
errCh1b
:=
s
.
GetRunner
(
scenario1b
.
ctx
,
scenario1b
.
req
.
model
,
scenario1b
.
req
.
opts
,
scenario1b
.
req
.
sessionDuration
)
require
.
Len
(
t
,
s
.
pendingReqCh
,
1
)
require
.
Len
(
t
,
s
.
pendingReqCh
,
1
)
require
.
Len
(
t
,
successCh1b
,
0
)
require
.
Empty
(
t
,
successCh1b
)
require
.
Len
(
t
,
errCh1b
,
1
)
require
.
Len
(
t
,
errCh1b
,
1
)
err
:=
<-
errCh1b
err
:=
<-
errCh1b
require
.
Contains
(
t
,
err
.
Error
(),
"server busy"
)
require
.
Contains
(
t
,
err
.
Error
(),
"server busy"
)
...
@@ -340,8 +339,8 @@ func TestGetRunner(t *testing.T) {
...
@@ -340,8 +339,8 @@ func TestGetRunner(t *testing.T) {
select
{
select
{
case
resp
:=
<-
successCh1a
:
case
resp
:=
<-
successCh1a
:
require
.
Equal
(
t
,
resp
.
llama
,
scenario1a
.
srv
)
require
.
Equal
(
t
,
resp
.
llama
,
scenario1a
.
srv
)
require
.
Len
(
t
,
s
.
pendingReqCh
,
0
)
require
.
Empty
(
t
,
s
.
pendingReqCh
)
require
.
Len
(
t
,
errCh1a
,
0
)
require
.
Empty
(
t
,
errCh1a
)
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
t
.
Errorf
(
"timeout"
)
t
.
Errorf
(
"timeout"
)
}
}
...
@@ -355,9 +354,9 @@ func TestGetRunner(t *testing.T) {
...
@@ -355,9 +354,9 @@ func TestGetRunner(t *testing.T) {
successCh1c
,
errCh1c
:=
s
.
GetRunner
(
scenario1c
.
ctx
,
scenario1c
.
req
.
model
,
scenario1c
.
req
.
opts
,
scenario1c
.
req
.
sessionDuration
)
successCh1c
,
errCh1c
:=
s
.
GetRunner
(
scenario1c
.
ctx
,
scenario1c
.
req
.
model
,
scenario1c
.
req
.
opts
,
scenario1c
.
req
.
sessionDuration
)
// Starts in pending channel, then should be quickly processsed to return an error
// Starts in pending channel, then should be quickly processsed to return an error
time
.
Sleep
(
5
*
time
.
Millisecond
)
time
.
Sleep
(
5
*
time
.
Millisecond
)
require
.
Len
(
t
,
successCh1c
,
0
)
require
.
Empty
(
t
,
successCh1c
)
s
.
loadedMu
.
Lock
()
s
.
loadedMu
.
Lock
()
require
.
Len
(
t
,
s
.
loaded
,
0
)
require
.
Empty
(
t
,
s
.
loaded
)
s
.
loadedMu
.
Unlock
()
s
.
loadedMu
.
Unlock
()
require
.
Len
(
t
,
errCh1c
,
1
)
require
.
Len
(
t
,
errCh1c
,
1
)
err
=
<-
errCh1c
err
=
<-
errCh1c
...
@@ -386,8 +385,8 @@ func TestPrematureExpired(t *testing.T) {
...
@@ -386,8 +385,8 @@ func TestPrematureExpired(t *testing.T) {
select
{
select
{
case
resp
:=
<-
successCh1a
:
case
resp
:=
<-
successCh1a
:
require
.
Equal
(
t
,
resp
.
llama
,
scenario1a
.
srv
)
require
.
Equal
(
t
,
resp
.
llama
,
scenario1a
.
srv
)
require
.
Len
(
t
,
s
.
pendingReqCh
,
0
)
require
.
Empty
(
t
,
s
.
pendingReqCh
)
require
.
Len
(
t
,
errCh1a
,
0
)
require
.
Empty
(
t
,
errCh1a
)
s
.
loadedMu
.
Lock
()
s
.
loadedMu
.
Lock
()
require
.
Len
(
t
,
s
.
loaded
,
1
)
require
.
Len
(
t
,
s
.
loaded
,
1
)
s
.
loadedMu
.
Unlock
()
s
.
loadedMu
.
Unlock
()
...
@@ -401,9 +400,9 @@ func TestPrematureExpired(t *testing.T) {
...
@@ -401,9 +400,9 @@ func TestPrematureExpired(t *testing.T) {
time
.
Sleep
(
20
*
time
.
Millisecond
)
time
.
Sleep
(
20
*
time
.
Millisecond
)
require
.
LessOrEqual
(
t
,
len
(
s
.
finishedReqCh
),
1
)
require
.
LessOrEqual
(
t
,
len
(
s
.
finishedReqCh
),
1
)
time
.
Sleep
(
10
*
time
.
Millisecond
)
time
.
Sleep
(
10
*
time
.
Millisecond
)
require
.
Len
(
t
,
s
.
finishedReqCh
,
0
)
require
.
Empty
(
t
,
s
.
finishedReqCh
)
s
.
loadedMu
.
Lock
()
s
.
loadedMu
.
Lock
()
require
.
Len
(
t
,
s
.
loaded
,
0
)
require
.
Empty
(
t
,
s
.
loaded
)
s
.
loadedMu
.
Unlock
()
s
.
loadedMu
.
Unlock
()
// also shouldn't happen in real life
// also shouldn't happen in real life
...
@@ -487,7 +486,6 @@ func TestFindRunnerToUnload(t *testing.T) {
...
@@ -487,7 +486,6 @@ func TestFindRunnerToUnload(t *testing.T) {
r2
.
refCount
=
1
r2
.
refCount
=
1
resp
=
s
.
findRunnerToUnload
()
resp
=
s
.
findRunnerToUnload
()
require
.
Equal
(
t
,
r1
,
resp
)
require
.
Equal
(
t
,
r1
,
resp
)
}
}
func
TestNeedsReload
(
t
*
testing
.
T
)
{
func
TestNeedsReload
(
t
*
testing
.
T
)
{
...
...
server/upload.go
View file @
89d99001
...
@@ -146,7 +146,7 @@ func (b *blobUpload) Run(ctx context.Context, opts *registryOptions) {
...
@@ -146,7 +146,7 @@ func (b *blobUpload) Run(ctx context.Context, opts *registryOptions) {
case
requestURL
:=
<-
b
.
nextURL
:
case
requestURL
:=
<-
b
.
nextURL
:
g
.
Go
(
func
()
error
{
g
.
Go
(
func
()
error
{
var
err
error
var
err
error
for
try
:=
0
;
try
<
maxRetries
;
try
++
{
for
try
:=
range
maxRetries
{
err
=
b
.
uploadPart
(
inner
,
http
.
MethodPatch
,
requestURL
,
part
,
opts
)
err
=
b
.
uploadPart
(
inner
,
http
.
MethodPatch
,
requestURL
,
part
,
opts
)
switch
{
switch
{
case
errors
.
Is
(
err
,
context
.
Canceled
)
:
case
errors
.
Is
(
err
,
context
.
Canceled
)
:
...
@@ -190,7 +190,7 @@ func (b *blobUpload) Run(ctx context.Context, opts *registryOptions) {
...
@@ -190,7 +190,7 @@ func (b *blobUpload) Run(ctx context.Context, opts *registryOptions) {
headers
.
Set
(
"Content-Type"
,
"application/octet-stream"
)
headers
.
Set
(
"Content-Type"
,
"application/octet-stream"
)
headers
.
Set
(
"Content-Length"
,
"0"
)
headers
.
Set
(
"Content-Length"
,
"0"
)
for
try
:=
0
;
try
<
maxRetries
;
try
++
{
for
try
:=
range
maxRetries
{
var
resp
*
http
.
Response
var
resp
*
http
.
Response
resp
,
err
=
makeRequestWithRetry
(
ctx
,
http
.
MethodPut
,
requestURL
,
headers
,
nil
,
opts
)
resp
,
err
=
makeRequestWithRetry
(
ctx
,
http
.
MethodPut
,
requestURL
,
headers
,
nil
,
opts
)
if
errors
.
Is
(
err
,
context
.
Canceled
)
{
if
errors
.
Is
(
err
,
context
.
Canceled
)
{
...
@@ -253,7 +253,7 @@ func (b *blobUpload) uploadPart(ctx context.Context, method string, requestURL *
...
@@ -253,7 +253,7 @@ func (b *blobUpload) uploadPart(ctx context.Context, method string, requestURL *
}
}
// retry uploading to the redirect URL
// retry uploading to the redirect URL
for
try
:=
0
;
try
<
maxRetries
;
try
++
{
for
try
:=
range
maxRetries
{
err
=
b
.
uploadPart
(
ctx
,
http
.
MethodPut
,
redirectURL
,
part
,
nil
)
err
=
b
.
uploadPart
(
ctx
,
http
.
MethodPut
,
redirectURL
,
part
,
nil
)
switch
{
switch
{
case
errors
.
Is
(
err
,
context
.
Canceled
)
:
case
errors
.
Is
(
err
,
context
.
Canceled
)
:
...
@@ -391,7 +391,7 @@ func uploadBlob(ctx context.Context, mp ModelPath, layer *Layer, opts *registryO
...
@@ -391,7 +391,7 @@ func uploadBlob(ctx context.Context, mp ModelPath, layer *Layer, opts *registryO
return
err
return
err
}
}
//
nolint:
contextcheck
//nolint:contextcheck
go
upload
.
Run
(
context
.
Background
(),
opts
)
go
upload
.
Run
(
context
.
Background
(),
opts
)
}
}
...
...
types/model/name_test.go
View file @
89d99001
...
@@ -268,7 +268,6 @@ func TestNameIsValidPart(t *testing.T) {
...
@@ -268,7 +268,6 @@ func TestNameIsValidPart(t *testing.T) {
}
}
})
})
}
}
}
}
func
TestFilepathAllocs
(
t
*
testing
.
T
)
{
func
TestFilepathAllocs
(
t
*
testing
.
T
)
{
...
@@ -325,7 +324,7 @@ func TestParseNameFromFilepath(t *testing.T) {
...
@@ -325,7 +324,7 @@ func TestParseNameFromFilepath(t *testing.T) {
filepath
.
Join
(
"host:port"
,
"namespace"
,
"model"
,
"tag"
)
:
{
Host
:
"host:port"
,
Namespace
:
"namespace"
,
Model
:
"model"
,
Tag
:
"tag"
},
filepath
.
Join
(
"host:port"
,
"namespace"
,
"model"
,
"tag"
)
:
{
Host
:
"host:port"
,
Namespace
:
"namespace"
,
Model
:
"model"
,
Tag
:
"tag"
},
filepath
.
Join
(
"namespace"
,
"model"
,
"tag"
)
:
{},
filepath
.
Join
(
"namespace"
,
"model"
,
"tag"
)
:
{},
filepath
.
Join
(
"model"
,
"tag"
)
:
{},
filepath
.
Join
(
"model"
,
"tag"
)
:
{},
filepath
.
Join
(
"model"
)
:
{},
"model"
:
{},
filepath
.
Join
(
".."
,
".."
,
"model"
,
"tag"
)
:
{},
filepath
.
Join
(
".."
,
".."
,
"model"
,
"tag"
)
:
{},
filepath
.
Join
(
""
,
"namespace"
,
"."
,
"tag"
)
:
{},
filepath
.
Join
(
""
,
"namespace"
,
"."
,
"tag"
)
:
{},
filepath
.
Join
(
"."
,
"."
,
"."
,
"."
)
:
{},
filepath
.
Join
(
"."
,
"."
,
"."
,
"."
)
:
{},
...
@@ -382,7 +381,6 @@ func FuzzName(f *testing.F) {
...
@@ -382,7 +381,6 @@ func FuzzName(f *testing.F) {
t
.
Errorf
(
"String() = %q; want %q"
,
n
.
String
(),
s
)
t
.
Errorf
(
"String() = %q; want %q"
,
n
.
String
(),
s
)
}
}
}
}
})
})
}
}
...
...
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment