File size: 11,258 Bytes
2fc4496 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# %%
# %cd ~/docs/0425-ml_summit/scripts/
import plotly.express as px
from plotly.graph_objs import Figure, FigureWidget
import datasets
import pandas as pd
import huggingface_hub
import plotly.graph_objs as go
import numpy as np
from PIL import Image
FIGURES: dict[str, Figure] = {}
# %%
df = pd.read_csv("nlp_datas.csv")
fig = px.treemap(
df,
path=[px.Constant("nlp-datasets"), "task", "dataset"],
values="size",
# color="dataset",
# hover_data=["iso_alpha"],
# color_continuous_scale="RdBu",
)
FIGURES["nlp"] = fig
fig.update_layout(
paper_bgcolor="rgba(0,0,0,0)",
# autosize=True,
margin=dict(t=0, l=0, r=0, b=0),
# plot_bgcolor='rgba(0,0,0,0)',
)
# fig.update_traces(marker=dict(pattern=dict(shape=["|"], solidity=0.80)))
# fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
# figs.append(fig)
fig
# %%
df = pd.read_csv("llm.csv")
fig = px.treemap(
df,
path=[px.Constant("LLM"), "dataset"],
values="size",
# color="dataset",
# hover_data=["iso_alpha"],
# color_continuous_scale="RdBu",
)
FIGURES["gpt"] = fig
fig.update_layout(
paper_bgcolor="rgba(0,0,0,0)",
# autosize=True,
margin=dict(t=0, l=0, r=0, b=0),
# plot_bgcolor='rgba(0,0,0,0)',
)
# fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
fig
# %%
df = pd.read_csv("./seq-time.csv", index_col=0)
df.index = df.index.map(lambda x: eval(x.replace("k", "*1024")))
df["platformers"] = df["platformers"] / 7
df.drop([df.columns[-1]], axis=1, inplace=True)
df = df.reset_index(names="sequence length").melt(
id_vars="sequence length", var_name="model", value_name="time"
)
fig = px.line(df, x="sequence length", y="time", color="model")
FIGURES["seq-time"] = fig
fig.update_layout(
paper_bgcolor="rgba(0,0,0,0)",
# autosize=True,
margin=dict(t=0, l=0, r=0, b=0),
plot_bgcolor="rgba(0,0,0,0)",
legend_font=dict(color="white"),
)
fig.update_xaxes(
color="white",
)
fig.update_yaxes(
# showticklabels=False,
# zeroline=False,
# showline=False,
# griddash="4px",
# gridcolor="rgba(255,255,255,0.3)",
# title="Loss",
color="white",
)
fig
# %%
df = pd.read_csv("seq-tflops.csv", index_col=0)
# df['sequence length']
# df.index = df.index.map(lambda x: eval(x.replace("K", "*1024")))
df = df.reset_index(names="sequence length").melt(
id_vars="sequence length", var_name="model", value_name="tflops"
)
fig = px.bar(df, x="sequence length", y="tflops", color="model", barmode="group")
FIGURES["seq-tflops"] = fig
fig.update_layout(
paper_bgcolor="rgba(0,0,0,0)",
# autosize=True,
margin=dict(t=0, l=0, r=0, b=0),
plot_bgcolor="rgba(0,0,0,0)",
legend_font=dict(color="white"),
)
fig.update_xaxes(
color="white",
)
fig.update_yaxes(
# showticklabels=False,
# zeroline=False,
# showline=False,
# griddash="4px",
# gridcolor="rgba(255,255,255,0.3)",
# title="Loss",
color="white",
)
fig
# %%
df = datasets.load_dataset("SUSTech/webvid", split="train[:100]").to_pandas()
df = df.drop(["duration"], axis=1)
fig = go.Figure(
data=[
go.Table(
header=dict(
values=list(df.columns), fill_color="paleturquoise", align="left"
),
cells=dict(
values=[df[col] for col in df.columns],
fill_color="lavender",
align="left",
# alignsrc="center",
),
)
]
)
fig.update_layout(
paper_bgcolor="rgba(0,0,0,0)",
# autosize=True,
margin=dict(t=0, l=0, r=0, b=0),
# plot_bgcolor='rgba(0,0,0,0)',
)
# fig.show()
FIGURES["webvid"] = fig
# %%
fig = go.Figure()
data = {
"402-page transcripts from Apollo 11’s mission to the moon": 326914,
"44-minute silent Buster Keaton movie": 696417,
"more than 100,000 lines of code": 816767,
"Generate 1min video": 1000000,
}
df = pd.Series(data, name="token").to_frame().reset_index(names="task")
# df = px.data.gapminder().query("continent == 'Europe' and year == 2007 and pop > 2.e6")
fig = px.bar(
df,
y="token",
x="task",
text_auto=".2s",
# template="ggplot2",
# color="white",
# orientation="h",
)
FIGURES["token-bar"] = fig
fig.update_traces(
textfont_size=12,
textangle=0,
textposition="outside",
cliponaxis=False,
textfont_color="white",
)
fig.update_layout(
paper_bgcolor="rgba(0,0,0,0)",
# autosize=True,
margin=dict(t=0, l=0, r=0, b=0),
plot_bgcolor="rgba(0,0,0,0)",
legend_font=dict(color="white"),
)
fig.update_xaxes(
color="white",
# showticklabels=False,
zeroline=False,
showline=False,
showgrid=False,
title="",
)
fig.update_yaxes(
# showticklabels=False,
showline=False,
showgrid=False,
zeroline=False,
# griddash="4px",
# gridcolor="rgba(255,255,255,0.3)",
# title="Loss",
color="white",
)
fig
# %%
def generate_loss(steps, initial_loss, decay_rate, noise_factor):
loss = initial_loss * np.exp(-decay_rate * steps)
noise = noise_factor * loss * np.random.randn(*steps.shape)
return loss + noise
def splitpoints(total, split):
step = total // split
for i in range(split - 1):
yield slice(i * step, (i + 1) * step)
yield slice((i + 1) * step, None)
meta = [
{
"name": "2xDGX on aws",
"color": "red",
"icon": "../figures/gc.png",
},
{
"name": "16xDGX on aliyun",
"color": "orange",
"icon": "../figures/aws-white.png",
},
{
"name": "128xDGX on ucloud",
"color": "blue",
"icon": "../figures/aliyun.png",
},
]
steps = np.linspace(0, 1, 1000)
loss = generate_loss(steps, initial_loss=1, decay_rate=5, noise_factor=0.1)
fig = go.Figure()
# fig.update_layout(
# title="Training Loss by Steps", xaxis_title="Steps", yaxis_title="Loss"
# )
FIGURES["cloud-switch"] = fig
for i, idx in enumerate(splitpoints(1000, len(meta))):
fig.add_trace(
go.Scatter(
x=steps[idx],
y=loss[idx],
mode="lines",
name=meta[i]["name"],
line=dict(color=meta[i]["color"]),
)
)
fig.add_layout_image(
x=0.8,
sizex=0.2,
y=0.2,
sizey=0.2,
xref="paper",
yref="paper",
opacity=1.0,
layer="above",
source=Image.open("../figures/logo/ucloud.png"),
)
fig.add_layout_image(
x=0.17,
sizex=0.15,
y=0.7,
sizey=0.15,
xref="paper",
yref="paper",
opacity=1.0,
layer="above",
source=Image.open("../figures/aws-white.png"),
)
fig.add_layout_image(
x=0.43,
sizex=0.15,
y=0.3,
sizey=0.15,
xref="paper",
yref="paper",
opacity=1.0,
layer="above",
source=Image.open("../figures/aliyun.png"),
)
fig.update_layout(
showlegend=False,
paper_bgcolor="rgba(0,0,0,0)",
plot_bgcolor="rgba(255,255,255,0)",
# plot_bgcolor="rgba(255,255,0)",
# width=1120,
)
fig.update_xaxes(
showticklabels=False,
# ticklabelposition="inside left",
showline=False,
zeroline=False,
showgrid=False,
# title=dict(text="Steps", standoff=250),
automargin=True,
)
fig.update_yaxes(
showticklabels=False,
zeroline=False,
showline=False,
griddash="4px",
gridcolor="rgba(255,255,255,0.3)",
title="Loss",
color="white",
)
fig
# %%
def plot_gantt(df):
fig = px.timeline(df, x_start="Start", x_end="End", y="Task", color="Task")
fig.update_layout(xaxis_tickformat="%H:%M")
fig.update_layout(
showlegend=False,
paper_bgcolor="rgba(0,0,0,0)",
# plot_bgcolor="rgba(255,255,255,0.3)",
plot_bgcolor="rgba(255,255,255,0)",
# plot_bgcolor="rgba(255,255,0)",
# width=1120,
)
fig.update_xaxes(
showticklabels=False,
# ticklabelposition="inside left",
showline=False,
zeroline=False,
showgrid=False,
# title=dict(text="Steps", standoff=250),
automargin=True,
)
fig.update_yaxes(
# showticklabels=False,
zeroline=False,
showline=False,
griddash="4px",
gridcolor="rgba(0,0,0,0.3)",
title="",
color="white",
tickfont=dict(size=20),
)
return fig
# for hour slots randonly assign a task
num_rows = 1000
download_prop = 0.65
df = pd.DataFrame(
{"Start": pd.date_range("1-jan-2021", periods=num_rows, freq="4h")}
).assign(
End=lambda d: d.Start + pd.Timedelta(hours=1),
Task=np.random.choice(
["Read", "Transform"], num_rows, p=(download_prop, 1 - download_prop)
),
)
df.loc[0, "Task"] = "Read"
df.loc[len(df) - 1, "Task"] = "Transform"
df = df.groupby(df.Task.ne(df.Task.shift()).cumsum()).agg(
{"Start": "min", "End": "max", "Task": "first"}
)
timeline = df.copy()
# %%
df = timeline.copy()
ddi = pd.date_range(df.iloc[0].Start, end=df.iloc[-1].End, periods=10)
for start, end in zip(ddi[2:-1:3], ddi[3::3]):
df.loc[df["Start"].between(start, end), "Task"] = "Train"
df.loc[len(df) + 1] = pd.Series({"Start": start, "End": end, "Task": "Train"})
FIGURES["profile-naive"] = plot_gantt(df)
FIGURES["profile-naive"]
# %%
df = timeline.copy()
prop = 10
ddi = pd.date_range(df.iloc[0].Start, end=df.iloc[-1].End, periods=(prop + 1) * 10)
for start, end in zip(ddi[1 : -1 : prop + 1], ddi[prop :: prop + 1]):
df.loc[df["Start"].between(start, end), "Task"] = "Train"
df.loc[len(df) + 1] = pd.Series({"Start": start, "End": end, "Task": "Train"})
FIGURES["profile-old"] = plot_gantt(df)
FIGURES["profile-old"]
# %%
df = timeline.copy()
df.loc[len(df) + 1] = pd.Series(
{"Start": df.iloc[0].Start, "End": df.iloc[-1].Start, "Task": "Train"}
)
FIGURES["profile-stream"] = plot_gantt(df)
FIGURES["profile-stream"]
# %%
for k, v in FIGURES.items():
print(k)
v.write_html(
f"../components/{k}.qmd",
full_html=False,
include_plotlyjs="cdn",
)
# for i in range(100):
# print(i)
# %%
import qrcode
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles.moduledrawers.pil import RoundedModuleDrawer
from qrcode.image.styles.colormasks import RadialGradiantColorMask
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
qr.add_data("https://u.wechat.com/MAmdMGMYjGFC4-2ESxZ1oyw")
# img_1 = qr.make_image(image_factory=StyledPilImage, module_drawer=RoundedModuleDrawer())
img_2 = qr.make_image(
# image_factory=StyledPilImage,
# color_mask=RadialGradiantColorMask(),
fill_color="white",
back_color="transparent",
)
# img_3 = qr.make_image(
# image_factory=StyledPilImage, embeded_image_path="../figures/qr/code.png"
# )
img_2.save("../figures/qr/jing.png")
# %%
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
qr.add_data("mailto:[email protected]?subject=Hello&body=")
# img_1 = qr.make_image(image_factory=StyledPilImage, module_drawer=RoundedModuleDrawer())
img_2 = qr.make_image(
# image_factory=StyledPilImage,
# color_mask=RadialGradiantColorMask(),
fill_color="white",
back_color="transparent",
)
# img_3 = qr.make_image(
# image_factory=StyledPilImage, embeded_image_path="../figures/qr/code.png"
# )
img_2.save("../figures/qr/mail-data.png")
|