-
Notifications
You must be signed in to change notification settings - Fork 186
Inference UX, accept input data #1285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6c8dfb3
[deepsparse.infer] UX improvements, data only mode
b4b7ec6
fix bug on main
17168f6
draft, load files line by line, return iter, save up memory
horheynm 84b03f8
add inference
horheynm 8a69c5f
pass passing in files
horheynm 4091503
latest changes'
horheynm b0f65af
revert
horheynm 8ee765b
make new folder for inderence
horheynm 8a47e01
allow input to pass thru cli
horheynm 6957067
Merge branch 'main' into infer-ux-fixes
horheynm b429917
Update src/deepsparse/transformers/inference/infer.py
horheynm 1dc2ee3
remove hardcoded
horheynm 86a2daf
better error message
horheynm 939c6bc
clean up
horheynm 274570b
Merge branch 'main' into infer-ux-fixes
horheynm 7b1edfa
clean up, check kwargs
horheynm 064013a
Merge branch 'infer-ux-fixes' of github.com:neuralmagic/deepsparse in…
horheynm 8cab34f
Merge branch 'main' into infer-ux-fixes
horheynm 4699837
get rid of breakpoint()
horheynm 218b584
Merge branch 'infer-ux-fixes' of github.com:neuralmagic/deepsparse in…
horheynm ff4b48f
return type
horheynm 8243740
Merge branch 'main' into infer-ux-fixes
horheynm 2a4b972
typo
horheynm ad9e96d
Merge branch 'infer-ux-fixes' of github.com:neuralmagic/deepsparse in…
horheynm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
import csv | ||
import json | ||
import os | ||
from enum import Enum | ||
|
||
|
||
class InvalidPromptSourceDirectoryException(Exception): | ||
pass | ||
|
||
|
||
class PromptParser: | ||
class Extentions(Enum): | ||
TEXT = ".txt" | ||
CSV = ".csv" | ||
JSON = ".json" | ||
JSONL = ".jsonl" | ||
|
||
def __init__(self, filename: str): | ||
self.extention: self.Extentions = self._validate_and_return_extention(filename) | ||
self.filename: str = filename | ||
|
||
def parse_as_iterable(self): | ||
|
||
if self.extention == self.Extentions.TEXT: | ||
return self._parse_text() | ||
if self.extention == self.Extentions.CSV: | ||
return self._parse_csv() | ||
if self.extention == self.Extentions.JSON: | ||
return self._parse_json_list() | ||
if self.extention == self.Extentions.JSONL: | ||
return self._parse_jsonl() | ||
|
||
def _parse_text(self): | ||
with open(self.filename, "r") as file: | ||
for line in file: | ||
yield line.strip(), {} | ||
|
||
def _parse_csv(self): | ||
with open(self.filename, "r", newline="", encoding="utf-8-sig") as file: | ||
reader = csv.DictReader(file) | ||
for row in reader: | ||
yield row.get("prompt"), row | ||
|
||
def _parse_json_list(self): | ||
with open(self.filename, "r") as file: | ||
json_list = json.load(file) | ||
for json_object in json_list: | ||
yield json_object.get("prompt"), json_object | ||
|
||
def _parse_jsonl(self): | ||
with open(self.filename, "r") as file: | ||
for jsonl in file: | ||
jsonl_object = json.loads(jsonl) | ||
yield jsonl_object.get("prompt"), jsonl_object | ||
|
||
def _validate_and_return_extention(self, filename: str): | ||
if os.path.exists(filename): | ||
|
||
for extention in self.Extentions: | ||
if filename.endswith(extention.value): | ||
return extention | ||
|
||
raise InvalidPromptSourceDirectoryException( | ||
f"{filename} is not a valid source extract batched prompts" | ||
) | ||
raise FileNotFoundError |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.