Skip to content

Commit bb10bda

Browse files
committed
Initial changes
1 parent 2968532 commit bb10bda

File tree

7 files changed

+35
-25
lines changed

7 files changed

+35
-25
lines changed

src/lemonade/cache.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,17 @@ def checkpoint_to_model_name(checkpoint_name: str) -> str:
1717
return checkpoint_name.split("/")[1]
1818

1919

20-
def get_timestamp() -> str:
20+
def get_build_timestamp(build_time) -> str:
2121
"""
2222
Get a timestamp string in the format:
2323
<year>y_<month>m_<day>d_<hour>h_<minute>m_<second>s
2424
"""
25-
# Get the current time in GMT
26-
current_time = datetime.now(timezone.utc)
27-
2825
# Format the timestamp string
29-
timestamp = current_time.strftime("%Yy_%mm_%dd_%Hh_%Mm_%Ss")
26+
timestamp = build_time.strftime("%Yy_%mm_%dd_%Hh_%Mm_%Ss")
3027
return timestamp
3128

3229

33-
def build_name(input_name):
30+
def build_name(input_name, build_time):
3431
"""
3532
Name the lemonade build by concatenating these two factors:
3633
1. Sanitize the input name (typically a model checkpoint name) by
@@ -54,7 +51,7 @@ def build_name(input_name):
5451
input_name_sanitized = input_name_sanitized.replace(":", "-")
5552

5653
# Get the formatted timestamp string
57-
timestamp = get_timestamp()
54+
timestamp = get_build_timestamp(build_time)
5855

5956
return f"{input_name_sanitized}_{timestamp}"
6057

src/lemonade/cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import platform
3+
from datetime import datetime
34

45
# pylint: disable=C0413
56
# Prevent HF warnings from showing on every import
@@ -151,10 +152,12 @@ def main():
151152
first_tool_args.append("--input")
152153
first_tool_args.append(global_args["input"])
153154

155+
build_time = datetime.now().astimezone()
154156
state = State(
155157
cache_dir=os.path.abspath(global_args["cache_dir"]),
156-
build_name=cache.build_name(global_args["input"]),
158+
build_name=cache.build_name(global_args["input"], build_time),
157159
sequence_info=sequence.info,
160+
build_time=build_time,
158161
)
159162
sequence.launch(state)
160163
else:

src/lemonade/common/filesystem.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,13 @@ def get_available_builds(cache_dir):
187187

188188
check_cache_dir(cache_dir)
189189

190+
builds_dir = os.path.abspath(build.builds_dir(cache_dir))
191+
if not os.path.isdir(builds_dir):
192+
return []
193+
190194
builds = [
191195
pathlib.PurePath(build_name).name
192-
for build_name in os.listdir(os.path.abspath(build.builds_dir(cache_dir)))
196+
for build_name in os.listdir(builds_dir)
193197
if os.path.isdir(build.output_dir(cache_dir, build_name))
194198
and is_build_dir(cache_dir, build_name)
195199
]
@@ -228,7 +232,7 @@ class Keys:
228232
# Prefix for reporting the execution status of a tool
229233
# In the report this will look like tool_status:TOOL_NAME
230234
TOOL_STATUS = "tool_status"
231-
# Records the date and time of the evaluation after analysis but before
235+
# Records the local date and time of the evaluation after analysis but before
232236
# build and benchmark
233237
TIMESTAMP = "timestamp"
234238
# Records the logfile of any failed tool/benchmark

src/lemonade/sequence.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
import os
44
import platform
55
import copy
6-
from datetime import datetime
76
from typing import List, Dict, Optional
87

9-
import pytz
108
import psutil
119

1210
import lemonade.common.printing as printing
@@ -115,8 +113,7 @@ def launch(
115113
Executes the sequence of tools.
116114
"""
117115

118-
current_time = datetime.now()
119-
timestamp = current_time.strftime("%Y-%m-%d-%H%M%S")
116+
timestamp = state.build_time.strftime("%Y-%m-%d-%H%M%S")
120117
start_times = {"warmup": time.time()}
121118

122119
# Allow monitor to be globally disabled by an environment variable
@@ -161,11 +158,7 @@ def launch(
161158
state.save_stat(fs.Keys.BUILD_STATUS, build.FunctionStatus.INCOMPLETE)
162159

163160
# Save a timestamp so that we know the order of builds within a cache
164-
pacific_tz = pytz.timezone("America/Los_Angeles")
165-
state.save_stat(
166-
fs.Keys.TIMESTAMP,
167-
datetime.now(pacific_tz),
168-
)
161+
state.save_stat(fs.Keys.TIMESTAMP, state.build_time)
169162

170163
# Save the system information used for this build
171164
system_info = build.get_system_info_from_server()

src/lemonade/state.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import sys
3+
from datetime import datetime
34
from typing import Dict, Optional, Any
45
import yaml
56
import lemonade.common.build as build
@@ -61,6 +62,7 @@ def __init__(
6162
cache_dir: str,
6263
build_name: Optional[str] = None,
6364
sequence_info: Dict[str, Dict] = None,
65+
build_time: Optional[datetime] = None,
6466
**kwargs,
6567
):
6668

@@ -75,6 +77,9 @@ def __init__(
7577
self.cache_dir = parsed_cache_dir
7678
self.build_name = build_name
7779
self.sequence_info = sequence_info
80+
self.build_time = (
81+
datetime.now().astimezone() if build_time is None else build_time
82+
)
7883
self.lemonade_version = lemonade_version
7984
self.build_status = build.FunctionStatus.NOT_STARTED
8085
self.downcast_applied = False

src/lemonade/tools/report/llm_report.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66
from typing import List
77
import lemonade.common.printing as printing
8+
import lemonade.common.exceptions as exp
89
import lemonade.common.filesystem as fs
910
from lemonade.tools.management_tools import ManagementTool
1011
from lemonade.cache import DEFAULT_CACHE_DIR
@@ -148,7 +149,13 @@ def run(
148149
):
149150
# Process input arguments
150151
cache_dirs = [os.path.expanduser(dir) for dir in input_caches]
151-
cache_dirs = fs.expand_inputs(cache_dirs)
152+
try:
153+
cache_dirs = fs.expand_inputs(cache_dirs)
154+
except exp.ArgError as e:
155+
printing.log_info(
156+
f"No Lemonade cache folders exist for: {cache_dirs}. Error: {e}"
157+
)
158+
return
152159
report_dir = os.path.expanduser(output_dir)
153160

154161
if perf:

src/lemonade/tools/report/table.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,10 @@ def get_report_name(prefix: str = "") -> str:
585585
"""
586586
Returns the name of the .csv report
587587
"""
588-
day = datetime.now().day
589-
month = datetime.now().month
590-
year = datetime.now().year
588+
currentTime = datetime.now()
589+
day = currentTime.day
590+
month = currentTime.month
591+
year = currentTime.year
591592
date_key = f"{year}-{str(month).zfill(2)}-{str(day).zfill(2)}"
592593
return f"{prefix}{date_key}.csv"
593594

@@ -774,7 +775,7 @@ def include_stats(self, model_stats) -> bool:
774775
# Filter out build if it is too old
775776
if not self.days is None:
776777
build_day = model_stats[fs.Keys.TIMESTAMP]
777-
today = datetime.now(timezone.utc)
778+
today = datetime.now()
778779
delta = today - build_day
779780
if delta.days > self.days:
780781
return False
@@ -891,7 +892,7 @@ def matching_builds(build_stats_1: Dict, build_stats_2: Dict) -> bool:
891892

892893
@staticmethod
893894
def get_report_name() -> str:
894-
current_time = datetime.now(timezone.utc)
895+
current_time = datetime.now()
895896
timestamp = current_time.strftime("%Y-%m-%d-%H%M%S")
896897
return f"{timestamp}_perf.csv"
897898

0 commit comments

Comments
 (0)