Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -44,8 +44,7 @@ priority = {
|
|
44 |
def run_llava(prompt, pil_image, temperature, top_p, max_new_tokens):
|
45 |
image_size = pil_image.size
|
46 |
image_tensor = image_processor.preprocess(pil_image, return_tensors='pt')['pixel_values'].half().cuda()
|
47 |
-
#
|
48 |
-
image_tensor = image_tensor.to(model.device, dtype=torch.float16)
|
49 |
input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt")
|
50 |
input_ids = input_ids.unsqueeze(0).cuda()
|
51 |
with torch.inference_mode():
|
@@ -67,16 +66,16 @@ def run_llava(prompt, pil_image, temperature, top_p, max_new_tokens):
|
|
67 |
return outputs[0].strip()
|
68 |
|
69 |
|
70 |
-
def load_selected_model(model_path):
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
|
81 |
|
82 |
def get_conv_log_filename():
|
@@ -496,24 +495,25 @@ Set the environment variable `model` to change the model:
|
|
496 |
print(f"args: {args}")
|
497 |
concurrency_count = int(os.getenv("concurrency_count", 5))
|
498 |
api_key = os.getenv("token")
|
499 |
-
if api_key:
|
500 |
-
cmd = f"huggingface-cli login --token {api_key} --add-to-git-credential"
|
501 |
-
os.system(cmd)
|
502 |
-
else:
|
503 |
-
if '/workspace' not in sys.path:
|
504 |
-
sys.path.append('/workspace')
|
505 |
-
from llavaguard.hf_utils import set_up_env_and_token
|
506 |
|
507 |
-
api_key = set_up_env_and_token(read=True, write=False)
|
508 |
|
509 |
models = [
|
510 |
'LukasHug/LlavaGuard-7B-hf',
|
511 |
'LukasHug/LlavaGuard-13B-hf',
|
512 |
'LukasHug/LlavaGuard-34B-hf', ]
|
513 |
bits = int(os.getenv("bits", 16))
|
514 |
-
model = os.getenv("model", models[
|
515 |
available_devices = os.getenv("CUDA_VISIBLE_DEVICES", "0")
|
516 |
model_path, model_name = model, model.split("/")[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
517 |
|
518 |
print(f"Loading model {model_path}")
|
519 |
tokenizer, model, image_processor, context_len = load_pretrained_model(model_path, None, model_name, token=api_key)
|
@@ -535,4 +535,4 @@ Set the environment variable `model` to change the model:
|
|
535 |
print(e)
|
536 |
exit_status = 1
|
537 |
finally:
|
538 |
-
sys.exit(exit_status)
|
|
|
44 |
def run_llava(prompt, pil_image, temperature, top_p, max_new_tokens):
|
45 |
image_size = pil_image.size
|
46 |
image_tensor = image_processor.preprocess(pil_image, return_tensors='pt')['pixel_values'].half().cuda()
|
47 |
+
# image_tensor = image_tensor.to(model.device, dtype=torch.float16)
|
|
|
48 |
input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt")
|
49 |
input_ids = input_ids.unsqueeze(0).cuda()
|
50 |
with torch.inference_mode():
|
|
|
66 |
return outputs[0].strip()
|
67 |
|
68 |
|
69 |
+
# def load_selected_model(model_path):
|
70 |
+
# model_name = model_path.split("/")[-1]
|
71 |
+
# global tokenizer, model, image_processor, context_len
|
72 |
+
# with warnings.catch_warnings(record=True) as w:
|
73 |
+
# warnings.simplefilter("always")
|
74 |
+
# tokenizer, model, image_processor, context_len = load_pretrained_model(model_path, None, model_name)
|
75 |
+
# for warning in w:
|
76 |
+
# if "vision" not in str(warning.message).lower():
|
77 |
+
# print(warning.message)
|
78 |
+
# model.config.tokenizer_model_max_length = 2048 * 2
|
79 |
|
80 |
|
81 |
def get_conv_log_filename():
|
|
|
495 |
print(f"args: {args}")
|
496 |
concurrency_count = int(os.getenv("concurrency_count", 5))
|
497 |
api_key = os.getenv("token")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
498 |
|
|
|
499 |
|
500 |
models = [
|
501 |
'LukasHug/LlavaGuard-7B-hf',
|
502 |
'LukasHug/LlavaGuard-13B-hf',
|
503 |
'LukasHug/LlavaGuard-34B-hf', ]
|
504 |
bits = int(os.getenv("bits", 16))
|
505 |
+
model = os.getenv("model", models[0])
|
506 |
available_devices = os.getenv("CUDA_VISIBLE_DEVICES", "0")
|
507 |
model_path, model_name = model, model.split("/")[0]
|
508 |
+
if api_key:
|
509 |
+
cmd = f"huggingface-cli login --token {api_key} --add-to-git-credential"
|
510 |
+
os.system(cmd)
|
511 |
+
else:
|
512 |
+
if '/workspace' not in sys.path:
|
513 |
+
sys.path.append('/workspace')
|
514 |
+
from llavaguard.hf_utils import set_up_env_and_token
|
515 |
+
api_key = set_up_env_and_token(read=True, write=False)
|
516 |
+
model_path = '/common-repos/LlavaGuard/models/LlavaGuard-v1.1-7b-full/smid_and_crawled_v2_with_augmented_policies/json-v16/llava'
|
517 |
|
518 |
print(f"Loading model {model_path}")
|
519 |
tokenizer, model, image_processor, context_len = load_pretrained_model(model_path, None, model_name, token=api_key)
|
|
|
535 |
print(e)
|
536 |
exit_status = 1
|
537 |
finally:
|
538 |
+
sys.exit(exit_status)
|