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
text-generation-inference
Commits
775115e3
Unverified
Commit
775115e3
authored
Feb 01, 2023
by
OlivierDehaene
Committed by
GitHub
Feb 01, 2023
Browse files
feat(server): allow the server to use a local weight cache (#49)
parent
313194f6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
0 deletions
+13
-0
launcher/src/main.rs
launcher/src/main.rs
+6
-0
server/text_generation/utils.py
server/text_generation/utils.py
+7
-0
No files found.
launcher/src/main.rs
View file @
775115e3
...
@@ -313,6 +313,12 @@ fn shard_manager(
...
@@ -313,6 +313,12 @@ fn shard_manager(
env
.push
((
"HUGGINGFACE_HUB_CACHE"
.into
(),
huggingface_hub_cache
.into
()));
env
.push
((
"HUGGINGFACE_HUB_CACHE"
.into
(),
huggingface_hub_cache
.into
()));
};
};
// If the WEIGHTS_CACHE_OVERRIDE env var is set, pass it to the shard
// Useful when running inside a HuggingFace Inference Endpoint
if
let
Ok
(
weights_cache_override
)
=
env
::
var
(
"WEIGHTS_CACHE_OVERRIDE"
)
{
env
.push
((
"WEIGHTS_CACHE_OVERRIDE"
.into
(),
weights_cache_override
.into
()));
};
// If the CUDA_VISIBLE_DEVICES env var is set, pass it to the shard
// If the CUDA_VISIBLE_DEVICES env var is set, pass it to the shard
if
let
Ok
(
cuda_visible_devices
)
=
env
::
var
(
"CUDA_VISIBLE_DEVICES"
)
{
if
let
Ok
(
cuda_visible_devices
)
=
env
::
var
(
"CUDA_VISIBLE_DEVICES"
)
{
env
.push
((
"CUDA_VISIBLE_DEVICES"
.into
(),
cuda_visible_devices
.into
()));
env
.push
((
"CUDA_VISIBLE_DEVICES"
.into
(),
cuda_visible_devices
.into
()));
...
...
server/text_generation/utils.py
View file @
775115e3
...
@@ -25,6 +25,7 @@ from transformers.generation.logits_process import (
...
@@ -25,6 +25,7 @@ from transformers.generation.logits_process import (
from
text_generation.pb
import
generate_pb2
from
text_generation.pb
import
generate_pb2
WEIGHTS_CACHE_OVERRIDE
=
os
.
getenv
(
"WEIGHTS_CACHE_OVERRIDE"
,
None
)
class
Sampling
:
class
Sampling
:
def
__init__
(
self
,
seed
:
int
,
device
:
str
=
"cpu"
):
def
__init__
(
self
,
seed
:
int
,
device
:
str
=
"cpu"
):
...
@@ -230,6 +231,9 @@ def try_to_load_from_cache(model_name, revision, filename):
...
@@ -230,6 +231,9 @@ def try_to_load_from_cache(model_name, revision, filename):
def
weight_files
(
model_name
,
revision
=
None
,
extension
=
".safetensors"
):
def
weight_files
(
model_name
,
revision
=
None
,
extension
=
".safetensors"
):
"""Get the local safetensors filenames"""
"""Get the local safetensors filenames"""
if
WEIGHTS_CACHE_OVERRIDE
is
not
None
:
return
list
(
Path
(
WEIGHTS_CACHE_OVERRIDE
).
glob
(
f
"*
{
extension
}
"
))
filenames
=
weight_hub_files
(
model_name
,
revision
,
extension
)
filenames
=
weight_hub_files
(
model_name
,
revision
,
extension
)
files
=
[]
files
=
[]
for
filename
in
filenames
:
for
filename
in
filenames
:
...
@@ -249,6 +253,9 @@ def weight_files(model_name, revision=None, extension=".safetensors"):
...
@@ -249,6 +253,9 @@ def weight_files(model_name, revision=None, extension=".safetensors"):
def
download_weights
(
model_name
,
revision
=
None
,
extension
=
".safetensors"
):
def
download_weights
(
model_name
,
revision
=
None
,
extension
=
".safetensors"
):
"""Download the safetensors files from the hub"""
"""Download the safetensors files from the hub"""
if
WEIGHTS_CACHE_OVERRIDE
is
not
None
:
return
list
(
Path
(
WEIGHTS_CACHE_OVERRIDE
).
glob
(
f
"*
{
extension
}
"
))
filenames
=
weight_hub_files
(
model_name
,
revision
,
extension
)
filenames
=
weight_hub_files
(
model_name
,
revision
,
extension
)
download_function
=
partial
(
download_function
=
partial
(
...
...
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