-
Notifications
You must be signed in to change notification settings - Fork 593
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
Dummy inference engine #325 #331
Open
ji-cryptocafe
wants to merge
13
commits into
exo-explore:main
Choose a base branch
from
ji-cryptocafe:dummy-inference-branch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+240
−7
Open
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c02752f
Add DummyInferenceEngine implementation
ji-cryptocafe 7317424
Add tests for DummyInferenceEngine
ji-cryptocafe f5a7566
updated pytest settings in pyproject.toml and update dummyInferenceEn…
ji-cryptocafe 5abc446
updated pytest settings for random test
ji-cryptocafe 96510e7
Implemented DummyInferenceEngine with CLI support and fixed latency t…
ji-cryptocafe c66cad4
code cleanup
ji-cryptocafe a622a39
DummyInferenceEngine implements abstract class
ji-cryptocafe 6545903
Merge branch 'exo-explore:main' into dummy-inference-branch
ji-cryptocafe 76b03ef
Two versions of Dummy inference
ji-cryptocafe 56519b8
removed unused classes,
ji-cryptocafe 22bd9ad
dummyInferenceEngine
ji-cryptocafe 5a06b18
fixed class name error
ji-cryptocafe 7ad00ab
merged
ji-cryptocafe 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 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,32 @@ | ||
import random | ||
import asyncio | ||
import numpy as np | ||
|
||
class DummyInferenceEngine: | ||
def __init__(self, output_type="static", output_value=None, output_shape=(1,), latency_mean=0.1, latency_stddev=0.1): | ||
self.output_type = output_type | ||
self.output_value = output_value | ||
self.output_shape = output_shape | ||
self.latency_mean = latency_mean | ||
self.latency_stddev = latency_stddev | ||
|
||
# Validation for static output type | ||
if self.output_type == "static" and self.output_value is None: | ||
raise ValueError("output_value must be provided when output_type is 'static'.") | ||
|
||
async def run_inference(self): | ||
# Simulate latency | ||
latency = max(0, random.normalvariate(self.latency_mean, self.latency_stddev)) # Non-negative latency | ||
await asyncio.sleep(latency) | ||
|
||
# Generate output based on the specified output type | ||
if self.output_type == "static": | ||
return self.output_value # Return the static output | ||
elif self.output_type == "random": | ||
self.output_value = np.random.randn(*self.output_shape).tolist() # Generate random output and store it | ||
return self.output_value | ||
|
||
async def get_latency(self): | ||
# Simulate and return the latency | ||
return max(0, random.normalvariate(self.latency_mean, self.latency_stddev)) | ||
|
This file contains 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 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,60 @@ | ||
import asyncio | ||
import pytest | ||
from exo.inference.DummyInferenceEngine import DummyInferenceEngine | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_dummy_engine(): | ||
dummy_engine = DummyInferenceEngine(output_type="random", output_shape=(2, 2), latency_mean=0.5, latency_stddev=0.1) | ||
|
||
# Simulate inference | ||
output = await dummy_engine.run_inference() | ||
latency = await dummy_engine.get_latency() | ||
|
||
assert isinstance(output, list), "Output should be a list." | ||
assert isinstance(latency, float), "Latency should be a float." | ||
|
||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_dummy_inference_engine_static(): | ||
# Test with static output | ||
dummy_engine = DummyInferenceEngine(output_type="static", output_value=[1, 2, 3], latency_mean=0.2, latency_stddev=0.1) | ||
await dummy_engine.run_inference() # Simulate inference, check for errors | ||
assert dummy_engine.output_value == [1, 2, 3], "The static output should match the provided value." | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_dummy_inference_engine_random(): | ||
# Test with random output | ||
dummy_engine = DummyInferenceEngine(output_type="random", output_shape=(128, 128), latency_mean=0.1, latency_stddev=0.1) | ||
await dummy_engine.run_inference() # Simulate inference, check for errors | ||
output = dummy_engine.output_value | ||
|
||
# Check that the output is a list and has the correct shape | ||
assert isinstance(output, list), "Output should be a list." | ||
assert len(output) == 128, "Output should have the specified outer shape." | ||
|
||
# Check each sub-list for the correct length | ||
for sublist in output: | ||
assert isinstance(sublist, list), "Each output item should be a list." | ||
assert len(sublist) == 128, "Each output sub-list should have the specified inner shape." | ||
|
||
# Optionally check the type of each element | ||
for sublist in output: | ||
for element in sublist: | ||
assert isinstance(element, (float, int)), "Each element should be a float or int." | ||
|
||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_dummy_inference_engine_latency(): | ||
for i in range(10): | ||
# Test that latency is within expected range | ||
dummy_engine = DummyInferenceEngine(output_type="static", output_value=[1], latency_mean=0.1, latency_stddev=0.0) | ||
start_time = asyncio.get_event_loop().time() | ||
await dummy_engine.run_inference() | ||
elapsed_time = asyncio.get_event_loop().time() - start_time | ||
# Allow a small tolerance (e.g., 0.1 seconds) for system-level deviations | ||
tolerance = 0.1 | ||
assert abs(elapsed_time - 0.1) <= tolerance, f"Expected latency to be around 0.1s, but got {elapsed_time}s." |
This file contains 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 |
---|---|---|
|
@@ -41,7 +41,7 @@ | |
parser.add_argument("--chatgpt-api-port", type=int, default=8000, help="ChatGPT API port") | ||
parser.add_argument("--chatgpt-api-response-timeout", type=int, default=90, help="ChatGPT API response timeout in seconds") | ||
parser.add_argument("--max-generate-tokens", type=int, default=10000, help="Max tokens to generate in each request") | ||
parser.add_argument("--inference-engine", type=str, default=None, help="Inference engine to use") | ||
parser.add_argument("--inference-engine", type=str, default=None, help="Inference engine to use e.g. 'mlx', 'tinygrad', 'dummy')") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't actually resolve the inference engine to |
||
parser.add_argument("--disable-tui", action=argparse.BooleanOptionalAction, help="Disable TUI") | ||
parser.add_argument("--run-model", type=str, help="Specify a model to run directly") | ||
parser.add_argument("--prompt", type=str, help="Prompt for the model when using --run-model", default="Who are you?") | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to implement the
InferenceEngine
interface