Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Llama Recipes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
meta-llama
Llama Recipes
Commits
754b5d22
Commit
754b5d22
authored
1 year ago
by
Hamid Shojanazeri
Browse files
Options
Downloads
Patches
Plain Diff
clean up and typo fixes
parent
9b0eae40
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inference/inference.py
+4
-4
4 additions, 4 deletions
inference/inference.py
inference/safety_utils.py
+2
-2
2 additions, 2 deletions
inference/safety_utils.py
with
6 additions
and
6 deletions
inference/inference.py
+
4
−
4
View file @
754b5d22
...
...
@@ -31,7 +31,7 @@ def main(
length_penalty
:
int
=
1
,
#[optional] Exponential penalty to the length that is used with beam-based generation.
enable_azure_content_safety
:
bool
=
False
,
# Enable safety check with Azure content safety api
enable_sensitive_topics
:
bool
=
False
,
# Enable check for sensitive topics using AuditNLG APIs
enable_saleforce_content_safety
:
bool
=
True
,
# Enable safety check w
o
th Saleforce safety flan t5
enable_sale
s
force_content_safety
:
bool
=
True
,
# Enable safety check w
i
th Sale
s
force safety flan t5
max_padding_length
:
int
=
None
,
# the max padding length to be used with tokenizer padding the prompts.
**
kwargs
):
...
...
@@ -59,10 +59,11 @@ def main(
"
pad_token
"
:
"
<PAD>
"
,
}
)
model
.
resize_token_embeddings
(
model
.
config
.
vocab_size
+
1
)
safety_checker
=
get_safety_checker
(
enable_azure_content_safety
,
enable_sensitive_topics
,
enable_saleforce_content_safety
,
enable_sale
s
force_content_safety
,
)
# Safety check of the user prompt
...
...
@@ -77,7 +78,7 @@ def main(
if
not
is_safe
:
print
(
method
)
print
(
report
)
print
(
"
Skipping the inferece as the prompt is not safe.
"
)
print
(
"
Skipping the infere
n
ce as the prompt is not safe.
"
)
sys
.
exit
(
1
)
# Exit the program with an error status
if
peft_model
:
...
...
@@ -85,7 +86,6 @@ def main(
model
.
eval
()
batch
=
tokenizer
(
user_prompt
,
padding
=
'
max_length
'
,
truncation
=
True
,
max_length
=
max_padding_length
,
return_tensors
=
"
pt
"
)
model
.
resize_token_embeddings
(
model
.
config
.
vocab_size
+
1
)
batch
=
{
k
:
v
.
to
(
"
cuda
"
)
for
k
,
v
in
batch
.
items
()}
start
=
time
.
perf_counter
()
with
torch
.
no_grad
():
...
...
This diff is collapsed.
Click to expand it.
inference/safety_utils.py
+
2
−
2
View file @
754b5d22
...
...
@@ -154,14 +154,14 @@ class AzureSaftyChecker(object):
# Function to determine which safety checker to use based on the options selected
def
get_safety_checker
(
enable_azure_content_safety
,
enable_sensitive_topics
,
enable_saleforce_content_safety
,
enable_sale
s
force_content_safety
,
):
safety_checker
=
[]
if
enable_azure_content_safety
:
safety_checker
.
append
(
AzureSaftyChecker
())
if
enable_sensitive_topics
:
safety_checker
.
append
(
AuditNLGSensitiveTopics
())
if
enable_saleforce_content_safety
:
if
enable_sale
s
force_content_safety
:
safety_checker
.
append
(
SalesforceSafetyChecker
())
return
safety_checker
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment