From 0547093f069971141238e0fcdeb7874a10423a1c Mon Sep 17 00:00:00 2001
From: Yifan Zhao <yifanz16@illinois.edu>
Date: Mon, 1 Feb 2021 04:38:44 -0600
Subject: [PATCH] Create symlink correctly when the user sends relative path

---
 hpvm/projects/torch2hpvm/torch2hpvm/compile.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/hpvm/projects/torch2hpvm/torch2hpvm/compile.py b/hpvm/projects/torch2hpvm/torch2hpvm/compile.py
index bf1da0270b..59925541bb 100644
--- a/hpvm/projects/torch2hpvm/torch2hpvm/compile.py
+++ b/hpvm/projects/torch2hpvm/torch2hpvm/compile.py
@@ -139,11 +139,14 @@ class ModelExporter:
         import numpy as np
         from torch.utils.data import DataLoader
 
+        def link_from_to(from_: PathLike, to: PathLike):
+            from_, to = Path(from_), Path(to)
+            from_.unlink(missing_ok=True)
+            from_.symlink_to(to.absolute())
+
         if isinstance(dataset, BinDataset):
-            input_filename.unlink(missing_ok=True)
-            labels_filename.unlink(missing_ok=True)
-            Path(input_filename).symlink_to(dataset.input_file)
-            Path(labels_filename).symlink_to(dataset.labels_file)
+            link_from_to(input_filename, dataset.input_file)
+            link_from_to(labels_filename, dataset.labels_file)
             return
         inputs, labels = zip(*iter(DataLoader(dataset)))
         inputs = np.stack(inputs, axis=0)
-- 
GitLab