Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
predtuner
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
llvm
predtuner
Commits
9e26e065
Commit
9e26e065
authored
4 years ago
by
Yifan Zhao
Browse files
Options
Downloads
Patches
Plain Diff
Save model P1 with torch.save
parent
895fc7cd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
predtuner/modeledapp.py
+9
-30
9 additions, 30 deletions
predtuner/modeledapp.py
with
9 additions
and
30 deletions
predtuner/modeledapp.py
+
9
−
30
View file @
9e26e065
import
abc
import
json
import
logging
import
os
import
pickle
from
pathlib
import
Path
from
typing
import
Callable
,
Dict
,
Iterator
,
List
,
Optional
,
Tuple
,
Type
,
Union
...
...
@@ -239,7 +240,7 @@ class QoSModelP1(IQoSModel):
:param qos_metric: A function that compute a QoS level from the return value
of `tensor_output_getter`.
:param storage: A
`pickle` file
to store this model into, if the file doesn
'
t exist,
:param storage: A
file of PyTorch format
to store this model into, if the file doesn
'
t exist,
or load the model from if the file exists.
If not given, the model will not be stored.
"""
...
...
@@ -277,42 +278,22 @@ class QoSModelP1(IQoSModel):
return
float
(
self
.
qos_metric
(
ret
))
def
_init
(
self
):
if
self
.
storage
and
self
.
storage
.
is_file
():
self
.
delta_tensors
,
self
.
baseline_tensor
=
torch
.
load
(
self
.
storage
)
dt
=
self
.
delta_tensors
btensor
=
self
.
baseline_tensor
=
self
.
output_f
({})
if
self
.
storage
and
self
.
storage
.
is_file
():
for
op
,
knob
,
delta_tensor
in
self
.
_load
(
self
.
storage
):
dt
[
op
][
knob
]
=
delta_tensor
updated
=
False
for
op
,
knob
in
barred_ravel_knobs
(
self
.
app
):
if
dt
[
op
][
knob
]
is
not
None
:
continue
updated
=
True
delta_tensor
=
self
.
output_f
({
op
:
knob
})
-
btensor
dt
[
op
][
knob
]
=
delta_tensor
self
.
_try_append_save
(
self
.
storage
,
op
,
knob
,
delta_tensor
)
if
self
.
storage
and
updated
:
os
.
makedirs
(
self
.
storage
.
parent
,
exist_ok
=
True
)
torch
.
save
((
dt
,
btensor
),
self
.
storage
)
super
().
_init
()
def
_load
(
self
,
path
:
Path
)
->
Iterator
[
Tuple
[
str
,
str
,
torch
.
Tensor
]]:
msg_logger
.
info
(
f
"
Model
{
self
.
name
}
found saved model at
{
path
}
"
)
with
path
.
open
(
"
rb
"
)
as
f
:
while
True
:
try
:
op_name
,
knob_name
,
tensor
=
pickle
.
load
(
f
)
yield
op_name
,
knob_name
,
tensor
except
EOFError
:
return
@staticmethod
def
_try_append_save
(
path
:
Optional
[
Path
],
op_name
:
str
,
knob_name
:
str
,
tensor
:
torch
.
Tensor
):
import
os
if
not
path
:
return
if
not
path
.
parent
.
is_dir
():
os
.
makedirs
(
path
.
parent
)
with
path
.
open
(
"
ab
"
)
as
f
:
pickle
.
dump
((
op_name
,
knob_name
,
tensor
),
f
)
class
QoSModelP2
(
IQoSModel
):
"""
QoS model `P1` in ApproxTuner.
...
...
@@ -389,8 +370,6 @@ class QoSModelP2(IQoSModel):
self
.
baseline_qos
=
float
(
data
[
"
bqos
"
])
def
_save
(
self
,
path
:
Path
):
import
os
if
not
path
.
parent
.
is_dir
():
os
.
makedirs
(
path
.
parent
)
with
path
.
open
(
"
w
"
)
as
f
:
...
...
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