AI Models แบบ Scalable ด้วย PyTorch Lightning
Sergiy Tkachuk
Director, GenAI Productivity
ทำงานได้อิสระจาก Python
มีประสิทธิภาพในการใช้งานจริง
ตัวอย่าง:

ทำงานได้อิสระจาก Python
มีประสิทธิภาพในการใช้งานจริง
ตัวอย่าง:

วิธีแปลงโมเดลมี 2 แบบ:
torch.jit.trace: ใช้ข้อมูล input ตัวอย่างเพื่อ trace การทำงานtorch.jit.script: คอมไพล์โมเดลโดยวิเคราะห์โค้ด Pythonควรใช้เมื่อใด:
trace สำหรับโมเดลที่ไม่ซับซ้อนscript สำหรับโมเดลที่มี control flow (เช่น ลูป)import torch import torch.nn as nnclass SimpleModel(nn.Module): def forward(self, x): return x * 2model = SimpleModel() scripted_model = torch.jit.script(model)
$$
torch.jit.save: บันทึก scripted model ลงไฟล์torch.jit.load: โหลดโมเดลกลับมาเพื่อ inference$$
# Save the model
torch.jit.save(scripted_mod,"model.pt")
# Load the model
loaded_model=torch.jit.load("model.pt")
ตัวอย่าง Input:
[1.0, 2.0, 3.0]ตัวอย่าง Output:
[2.0, 4.0, 6.0]# Perform inference input_arr = [1.0, 2.0, 3.0] input_tensor = torch.tensor(input_arr)output = loaded_model(input_tensor) print(output)
$$
torch.jit.trace: ใช้กับโมเดล statictorch.jit.script: รองรับ control flow แบบ dynamictorch.jit.save: บันทึก scripted modeltorch.jit.load: โหลดกลับมาเพื่อ inferenceAI Models แบบ Scalable ด้วย PyTorch Lightning