Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
evoprompt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Grießhaber Daniel
evoprompt
Commits
59b65e5d
Commit
59b65e5d
authored
4 months ago
by
Grießhaber Daniel
Browse files
Options
Downloads
Patches
Plain Diff
calculate usage for hfchat models
parent
be7f82c0
No related branches found
No related tags found
1 merge request
!9
Hf usage
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
evoprompt/models.py
+20
-16
20 additions, 16 deletions
evoprompt/models.py
with
20 additions
and
16 deletions
evoprompt/models.py
+
20
−
16
View file @
59b65e5d
...
...
@@ -10,6 +10,7 @@ from abc import ABC, abstractmethod
from
argparse
import
ArgumentParser
from
collections.abc
import
Iterable
from
itertools
import
zip_longest
from
math
import
prod
from
pathlib
import
Path
from
typing
import
Any
,
Callable
,
ClassVar
...
...
@@ -500,19 +501,23 @@ class HfChat(ChatModel, LLMModel):
class
UsageGenerationPipeline
(
transformers
.
TextGenerationPipeline
):
pass
# def run_single(
# self, inputs, preprocess_params, forward_params, postprocess_params
# ):
# model_inputs = self.preprocess(inputs, **preprocess_params)
# print(model_inputs["input_ids"].shape)
# model_outputs = self.forward(model_inputs, **forward_params)
# print(type(model_outputs), model_outputs)
# outputs = self.postprocess(model_outputs, **postprocess_params)
# return outputs
# transformers.pipelines.SUPPORTED_TASKS["text-generation"][
# "impl"
# ] = UsageGenerationPipeline
def
run_single
(
self
,
inputs
,
preprocess_params
,
forward_params
,
postprocess_params
):
model_inputs
=
self
.
preprocess
(
inputs
,
**
preprocess_params
)
model_outputs
=
self
.
forward
(
model_inputs
,
**
forward_params
)
outputs
=
self
.
postprocess
(
model_outputs
,
**
postprocess_params
)
input_usage
=
prod
(
model_outputs
[
"
input_ids
"
].
shape
)
output_usage
=
prod
(
model_outputs
[
"
generated_sequence
"
].
shape
)
usage
=
ModelUsage
(
input_usage
,
output_usage
,
input_usage
+
output_usage
)
return
outputs
,
usage
transformers
.
pipelines
.
SUPPORTED_TASKS
[
"
text-generation
"
][
"
impl
"
]
=
UsageGenerationPipeline
self
.
_model_name
=
model
...
...
@@ -588,14 +593,13 @@ class HfChat(ChatModel, LLMModel):
# input(
# f"The input for the model will look like this:\n'{self.pipeline.tokenizer.apply_chat_template(model_call_kwargs["text_inputs"], tokenize=False, add_generation_prompt=True)}'"
# )
response
=
self
.
_call_model
(
response
,
usage
=
self
.
_call_model
(
self
.
pipeline
,
use_cache
=
use_cache
,
**
model_call_kwargs
,
)
response_text
=
response
[
0
][
"
generated_text
"
][
-
1
][
"
content
"
]
# no usage supported by HF pipeline; TODO manually compute usage?
usage
=
ModelUsage
()
return
response_text
,
usage
@property
...
...
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