Skip to content

Commit a7c93ab

Browse files
committed
Remove unnecessary config
Signed-off-by: Qifan Deng <[email protected]>
1 parent d7ddc48 commit a7c93ab

File tree

5 files changed

+32
-31
lines changed

5 files changed

+32
-31
lines changed

pkg/common/config.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,9 @@ type DatasetConf struct {
184184
// when path is empty Url will be checked
185185
Path string `yaml:"path" json:"path"`
186186
// Url is the URL to download the sqlite db file if set, default is empty
187+
// if Path is not provided and Url is provided, the file will be downloaded
188+
// to "USER_HOME/.llm-d/dataset.db"
187189
Url string `yaml:"url" json:"url"`
188-
// SavePath is the local path to save the downloaded sqlite db file
189-
// if Url is set but SavePath is not, "USER_HOME/.llm-d/dataset.db" will be used
190-
SavePath string `yaml:"save-path" json:"save-path"`
191190
}
192191

193192
type Metrics struct {

pkg/dataset/custom_dataset.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const (
5555
nGenTokensColType = "INTEGER"
5656
)
5757

58-
func (d *CustomDataset) downloadDataset(url string, savePath string) error {
58+
func (d *CustomDataset) downloadDataset(url string, path string) error {
5959
// Set up signal handling for Ctrl+C (SIGINT)
6060
ctx, cancel := context.WithCancel(context.Background())
6161
defer cancel()
@@ -70,7 +70,7 @@ func (d *CustomDataset) downloadDataset(url string, savePath string) error {
7070
cancel()
7171
}()
7272

73-
out, err := os.Create(savePath)
73+
out, err := os.Create(path)
7474
if err != nil {
7575
return err
7676
}
@@ -109,7 +109,7 @@ func (d *CustomDataset) downloadDataset(url string, savePath string) error {
109109
written, err := io.Copy(out, pr)
110110
if err != nil {
111111
// Remove incomplete file
112-
cerr := os.Remove(savePath)
112+
cerr := os.Remove(path)
113113
if cerr != nil {
114114
d.Logger.Error(cerr, "failed to remove incomplete file after download")
115115
}
@@ -121,7 +121,7 @@ func (d *CustomDataset) downloadDataset(url string, savePath string) error {
121121
}
122122
// Check if file size is zero or suspiciously small
123123
if written == 0 {
124-
cerr := os.Remove(savePath)
124+
cerr := os.Remove(path)
125125
if cerr != nil {
126126
d.Logger.Error(cerr, "failed to remove empty file after download")
127127
}
@@ -130,7 +130,7 @@ func (d *CustomDataset) downloadDataset(url string, savePath string) error {
130130

131131
// Ensure file is fully flushed and closed before returning success
132132
if err := out.Sync(); err != nil {
133-
cerr := os.Remove(savePath)
133+
cerr := os.Remove(path)
134134
if cerr != nil {
135135
d.Logger.Error(cerr, "failed to remove incomplete file after download")
136136
}
@@ -279,37 +279,39 @@ func (d *CustomDataset) connectToDB(path string) error {
279279
return nil
280280
}
281281

282-
func (d *CustomDataset) Init(path string, url string, savePath string) error {
282+
func (d *CustomDataset) Init(path string, url string) error {
283283
d.hasWarned = false
284-
if path != "" {
284+
if path != "" && url == "" {
285+
d.Logger.Info("Using dataset from", "path", path)
285286
return d.connectToDB(path)
286287
}
287288
if url != "" {
288-
if savePath == "" {
289+
d.Logger.Info("Url detected", "url", url)
290+
if path == "" {
289291
user, err := os.UserHomeDir()
290292
if err != nil {
291293
return fmt.Errorf("failed to get user home directory: %w", err)
292294
}
293-
savePath = filepath.Join(user, ".llm-d", "dataset.sqlite3")
295+
path = filepath.Join(user, ".llm-d", "dataset.sqlite3")
296+
d.Logger.Info("Using default for dataset", "path", path)
297+
} else {
298+
d.Logger.Info("Using provided path for dataset", "path", path)
294299
}
295300

296-
_, err := os.Stat(savePath)
301+
_, err := os.Stat(path)
297302
if err != nil {
298303
// file does not exist, download it
299-
folder := filepath.Dir(savePath)
304+
folder := filepath.Dir(path)
300305
err := os.MkdirAll(folder, 0755)
301306
if err != nil {
302307
return fmt.Errorf("failed to create parent directory: %w", err)
303308
}
304-
d.Logger.Info("Downloading dataset from URL", "url", url, "to", savePath)
305-
err = d.downloadDataset(url, savePath)
309+
err = d.downloadDataset(url, path)
306310
if err != nil {
307311
return fmt.Errorf("failed to download dataset: %w", err)
308312
}
309313
}
310-
d.Logger.Info("Using dataset from", "path", savePath)
311-
312-
return d.connectToDB(savePath)
314+
return d.connectToDB(path)
313315
}
314316
return errors.New("no dataset path or url provided")
315317
}

pkg/dataset/custom_dataset_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var _ = Describe("CustomDataset", Ordered, func() {
3838
var (
3939
dataset *CustomDataset
4040
file_folder string
41-
savePath string
41+
path string
4242
validDBPath string
4343
pathToInvalidDB string
4444
pathNotExist string
@@ -58,7 +58,7 @@ var _ = Describe("CustomDataset", Ordered, func() {
5858
},
5959
}
6060
file_folder = ".llm-d"
61-
savePath = file_folder + "/test.sqlite3"
61+
path = file_folder + "/test.sqlite3"
6262
err := os.MkdirAll(file_folder, os.ModePerm)
6363
Expect(err).NotTo(HaveOccurred())
6464
validDBPath = file_folder + "/test.valid.sqlite3"
@@ -83,22 +83,22 @@ var _ = Describe("CustomDataset", Ordered, func() {
8383

8484
It("should download file from url", func() {
8585
url := "https://llm-d.ai"
86-
err := dataset.downloadDataset(url, savePath)
86+
err := dataset.downloadDataset(url, path)
8787
Expect(err).NotTo(HaveOccurred())
88-
_, err = os.Stat(savePath)
88+
_, err = os.Stat(path)
8989
Expect(err).NotTo(HaveOccurred())
90-
err = os.Remove(savePath)
90+
err = os.Remove(path)
9191
Expect(err).NotTo(HaveOccurred())
9292
})
9393

9494
It("should not download file from url", func() {
9595
url := "https://256.256.256.256" // invalid url
96-
err := dataset.downloadDataset(url, savePath)
96+
err := dataset.downloadDataset(url, path)
9797
Expect(err).To(HaveOccurred())
9898
})
9999

100100
It("should successfully init dataset", func() {
101-
err := dataset.Init(validDBPath, "", "")
101+
err := dataset.Init(validDBPath, "")
102102
Expect(err).NotTo(HaveOccurred())
103103

104104
row := dataset.db.QueryRow("SELECT n_gen_tokens FROM llmd WHERE prompt_hash=X'74bf14c09c038321cba39717dae1dc732823ae4abd8e155959367629a3c109a8';")
@@ -173,7 +173,7 @@ var _ = Describe("CustomDataset", Ordered, func() {
173173
})
174174

175175
It("should return tokens for existing prompt", func() {
176-
err := dataset.Init(validDBPath, "", "")
176+
err := dataset.Init(validDBPath, "")
177177
Expect(err).NotTo(HaveOccurred())
178178

179179
req := &openaiserverapi.TextCompletionRequest{

pkg/dataset/dataset.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ var chatCompletionFakeResponses = []string{
7070

7171
type Dataset interface {
7272
// Init initializes the dataset using configs
73-
Init(path string, url string, savePath string) error
73+
Init(path string, url string) error
7474
// Close closes the dataset
7575
Close() error
7676
// GetTokens returns tokens for the given request and mode (echo or random)
@@ -280,7 +280,7 @@ type BaseDataset struct {
280280
Logger logr.Logger
281281
}
282282

283-
func (d *BaseDataset) Init(path string, url string, savePath string) error {
283+
func (d *BaseDataset) Init(path string, url string) error {
284284
return nil
285285
}
286286

pkg/llm-d-inference-sim/simulator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func (s *VllmSimulator) initDataset() error {
249249
Logger: s.logger,
250250
}
251251

252-
if s.config.Dataset.Path == "" && s.config.Dataset.Url == "" && s.config.Dataset.SavePath == "" {
252+
if s.config.Dataset.Path == "" && s.config.Dataset.Url == "" {
253253
s.logger.Info("No dataset provided, will generate random responses from preset text")
254254
s.dataset = randDataset
255255
} else {
@@ -259,7 +259,7 @@ func (s *VllmSimulator) initDataset() error {
259259
}
260260
}
261261

262-
if err := s.dataset.Init(s.config.Dataset.Path, s.config.Dataset.Url, s.config.Dataset.SavePath); err != nil {
262+
if err := s.dataset.Init(s.config.Dataset.Path, s.config.Dataset.Url); err != nil {
263263
return fmt.Errorf("dataset initialization error: %w", err)
264264
}
265265
return nil

0 commit comments

Comments
 (0)