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
orangecat
ollama
Commits
630bb75d
"torchvision/vscode:/vscode.git/clone" did not exist on "3c81d474a2525b11356ca1dde299a9b1ab3715c6"
Commit
630bb75d
authored
Oct 10, 2023
by
Michael Yang
Browse files
dynamically size download parts based on file size
parent
a2055a1e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
5 deletions
+17
-5
server/download.go
server/download.go
+17
-5
No files found.
server/download.go
View file @
630bb75d
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"golang.org/x/sync/errgroup"
"golang.org/x/sync/errgroup"
"github.com/jmorganca/ollama/api"
"github.com/jmorganca/ollama/api"
"github.com/jmorganca/ollama/format"
)
)
var
blobDownloadManager
sync
.
Map
var
blobDownloadManager
sync
.
Map
...
@@ -47,6 +48,12 @@ type blobDownloadPart struct {
...
@@ -47,6 +48,12 @@ type blobDownloadPart struct {
*
blobDownload
`json:"-"`
*
blobDownload
`json:"-"`
}
}
const
(
numDownloadParts
=
64
minDownloadPartSize
int64
=
32
*
1000
*
1000
maxDownloadPartSize
int64
=
256
*
1000
*
1000
)
func
(
p
*
blobDownloadPart
)
Name
()
string
{
func
(
p
*
blobDownloadPart
)
Name
()
string
{
return
strings
.
Join
([]
string
{
return
strings
.
Join
([]
string
{
p
.
blobDownload
.
Name
,
"partial"
,
strconv
.
Itoa
(
p
.
N
),
p
.
blobDownload
.
Name
,
"partial"
,
strconv
.
Itoa
(
p
.
N
),
...
@@ -92,9 +99,15 @@ func (b *blobDownload) Prepare(ctx context.Context, requestURL *url.URL, opts *R
...
@@ -92,9 +99,15 @@ func (b *blobDownload) Prepare(ctx context.Context, requestURL *url.URL, opts *R
b
.
Total
,
_
=
strconv
.
ParseInt
(
resp
.
Header
.
Get
(
"Content-Length"
),
10
,
64
)
b
.
Total
,
_
=
strconv
.
ParseInt
(
resp
.
Header
.
Get
(
"Content-Length"
),
10
,
64
)
var
offset
int64
var
size
=
b
.
Total
/
numDownloadParts
var
size
int64
=
64
*
1024
*
1024
switch
{
case
size
<
minDownloadPartSize
:
size
=
minDownloadPartSize
case
size
>
maxDownloadPartSize
:
size
=
maxDownloadPartSize
}
var
offset
int64
for
offset
<
b
.
Total
{
for
offset
<
b
.
Total
{
if
offset
+
size
>
b
.
Total
{
if
offset
+
size
>
b
.
Total
{
size
=
b
.
Total
-
offset
size
=
b
.
Total
-
offset
...
@@ -108,7 +121,7 @@ func (b *blobDownload) Prepare(ctx context.Context, requestURL *url.URL, opts *R
...
@@ -108,7 +121,7 @@ func (b *blobDownload) Prepare(ctx context.Context, requestURL *url.URL, opts *R
}
}
}
}
log
.
Printf
(
"downloading %s in %d part(s)"
,
b
.
Digest
[
7
:
19
],
len
(
b
.
Parts
))
log
.
Printf
(
"downloading %s in %d
%s
part(s)"
,
b
.
Digest
[
7
:
19
],
len
(
b
.
Parts
)
,
format
.
HumanBytes
(
b
.
Parts
[
0
]
.
Size
)
)
return
nil
return
nil
}
}
...
@@ -126,8 +139,7 @@ func (b *blobDownload) Run(ctx context.Context, requestURL *url.URL, opts *Regis
...
@@ -126,8 +139,7 @@ func (b *blobDownload) Run(ctx context.Context, requestURL *url.URL, opts *Regis
file
.
Truncate
(
b
.
Total
)
file
.
Truncate
(
b
.
Total
)
g
,
_
:=
errgroup
.
WithContext
(
ctx
)
g
,
_
:=
errgroup
.
WithContext
(
ctx
)
// TODO(mxyng): download concurrency should be configurable
g
.
SetLimit
(
numDownloadParts
)
g
.
SetLimit
(
64
)
for
i
:=
range
b
.
Parts
{
for
i
:=
range
b
.
Parts
{
part
:=
b
.
Parts
[
i
]
part
:=
b
.
Parts
[
i
]
if
part
.
Completed
==
part
.
Size
{
if
part
.
Completed
==
part
.
Size
{
...
...
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