Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Legal Term Extraction
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ala
Legal Term Extraction
Commits
92649128
Commit
92649128
authored
1 year ago
by
jbreton
Browse files
Options
Downloads
Patches
Plain Diff
Change S4 workflow & add mistral7b
parent
2ab683d6
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+3
-1
3 additions, 1 deletion
.gitignore
models/Mistral-7B-Instruct-v0.2/.gitkeep
+0
-0
0 additions, 0 deletions
models/Mistral-7B-Instruct-v0.2/.gitkeep
models/download_model.py
+2
-1
2 additions, 1 deletion
models/download_model.py
modules/llm/s4.py
+17
-34
17 additions, 34 deletions
modules/llm/s4.py
with
22 additions
and
36 deletions
.gitignore
+
3
−
1
View file @
92649128
...
...
@@ -161,4 +161,6 @@ cython_debug/
temp
models/Mixtral-8x7B-Instruct-v0.1/*
!models/Mixtral-8x7B-Instruct-v0.1/.gitkeep
\ No newline at end of file
!models/Mixtral-8x7B-Instruct-v0.1/.gitkeep
models/Mistral-7B-Instruct-v0.2/*
!models/Mistral-7B-Instruct-v0.2/.gitkeep
This diff is collapsed.
Click to expand it.
models/Mistral-7B-Instruct-v0.2/.gitkeep
0 → 100644
+
0
−
0
View file @
92649128
This diff is collapsed.
Click to expand it.
models/download_model.py
+
2
−
1
View file @
92649128
from
huggingface_hub
import
snapshot_download
snapshot_download
(
repo_id
=
"
mistralai/Mixtral-8x7B-Instruct-v0.1
"
,
cache_dir
=
"
../temp
"
,
local_dir
=
"
./Mixtral-8x7B-Instruct-v0.1
"
)
\ No newline at end of file
#snapshot_download(repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1", cache_dir="../temp", local_dir="./Mixtral-8x7B-Instruct-v0.1")
snapshot_download
(
repo_id
=
"
mistralai/Mistral-7B-Instruct-v0.2
"
,
cache_dir
=
"
../temp
"
,
local_dir
=
"
./Mistral-7B-Instruct-v0.2
"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
modules/llm/s4.py
+
17
−
34
View file @
92649128
import
json
from
alive_progress
import
alive_bar
from
torch
import
bfloat16
import
torch
import
transformers
import
bitsandbytes
,
flash_attn
model_id
=
"
./models/
m
ixtral-8x7
b
"
model_id
=
"
.
./..
/models/
M
ixtral-8x7
B-Instruct-v0.1
"
model
=
transformers
.
AutoModelForCausalLM
.
from_pretrained
(
model_id
,
...
...
@@ -24,11 +23,12 @@ generate_text = transformers.pipeline(
return_full_text
=
False
,
# if using langchain set True
task
=
"
text-generation
"
,
# we pass model parameters here too
temperature
=
1
,
# 'randomness' of outputs, 0.0 is the min and 1.0 the max
do_sample
=
True
,
temperature
=
0.5
,
# 'randomness' of outputs, 0.0 is the min and 1.0 the max
top_p
=
0.15
,
# select from top tokens whose probability add up to 15%
top_k
=
0
,
# select from top 0 tokens (because zero, relies on top_p)
max_new_tokens
=
512
,
# max number of tokens to generate in the output
repetition_penalty
=
1.
1
# if output begins repeating increase
max_new_tokens
=
4096
,
# max number of tokens to generate in the output
repetition_penalty
=
1.
0
# if output begins repeating increase
)
inst
=
"""
...
...
@@ -65,42 +65,25 @@ def instruction_format(sys_message: str, query: str):
return
f
'
<s> [INST]
{
sys_message
}
[/INST]
\n
User:
{
query
}
\n
Assistant:
'
with
open
(
'
./data/
data
QS.json
'
,
'
r
'
,
encoding
=
'
utf-8
'
)
as
file
:
with
open
(
'
.
./..
/data/
eval
QS.json
'
,
'
r
'
,
encoding
=
'
utf-8
'
)
as
file
:
loaded
=
json
.
load
(
file
)
input
=
[]
output
=
{}
with
alive_bar
(
len
(
loaded
))
as
bar
:
for
sentence
in
loaded
:
try
:
input_prompt
=
instruction_format
(
inst
,
sentence
)
res
=
generate_text
(
input_prompt
)
input
.
append
(
instruction_format
(
inst
,
sentence
))
bar
(
)
print
(
"
Input creation finished
"
)
jsonOutput
=
res
[
0
][
"
generate
d
_text
"
]
res
=
generate_text
(
input
)
if
"
Action
"
in
jsonOutput
:
jsonOutput
[
"
action
"
]
=
jsonOutput
.
pop
(
"
Action
"
)
if
"
Acteur
"
in
jsonOutput
:
jsonOutput
[
"
actor
"
]
=
jsonOutput
.
pop
(
"
Acteur
"
)
if
"
Objet
"
in
jsonOutput
:
jsonOutput
[
"
artifact
"
]
=
jsonOutput
.
pop
(
"
Objet
"
)
if
"
Condition
"
in
jsonOutput
:
jsonOutput
[
"
condition
"
]
=
jsonOutput
.
pop
(
"
Condition
"
)
if
"
Définition
"
in
jsonOutput
:
jsonOutput
[
"
definition
"
]
=
jsonOutput
.
pop
(
"
Définition
"
)
if
"
Lieu
"
in
jsonOutput
:
jsonOutput
[
"
location
"
]
=
jsonOutput
.
pop
(
"
Lieu
"
)
if
"
Modalité
"
in
jsonOutput
:
jsonOutput
[
"
modality
"
]
=
jsonOutput
.
pop
(
"
Modalité
"
)
if
"
Référence
"
in
jsonOutput
:
jsonOutput
[
"
reference
"
]
=
jsonOutput
.
pop
(
"
Référence
"
)
if
"
Temps
"
in
jsonOutput
:
jsonOutput
[
"
time
"
]
=
jsonOutput
.
pop
(
"
Temps
"
)
i
=
0
for
sentence
in
loaded
:
output
[
sentence
]
=
res
[
i
][
0
][
"
generated_text
"
]
i
+=
1
output
[
sentence
]
=
jsonOutput
except
Exception
as
e
:
print
(
f
"
Erreur avec la phrase :
{
sentence
}
|
{
e
}
"
)
bar
()
with
open
(
'
./results/S4/MIXTRAL_answers.json
'
,
'
w
'
,
encoding
=
'
utf-8
'
)
as
file
:
with
open
(
'
.
./..
/results/S4/MIXTRAL_
raw_
answers.json
'
,
'
w
'
,
encoding
=
'
utf-8
'
)
as
file
:
json
.
dump
(
output
,
file
)
# in 44:36.6 (0.08/s)
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