-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #406 from rhatdan/quadlet
Make quadlets work with OCI images
- Loading branch information
Showing
9 changed files
with
213 additions
and
48 deletions.
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 |
---|---|---|
|
@@ -9,3 +9,6 @@ ramalama/*.patch | |
dist | ||
.#* | ||
venv/ | ||
*.container | ||
*.image | ||
*.volume |
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
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
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,82 @@ | ||
import os | ||
|
||
from ramalama.common import default_image | ||
|
||
|
||
class Quadlet: | ||
def __init__(self, model, args, exec_args): | ||
self.ai_image = model | ||
if hasattr(args, "MODEL"): | ||
self.ai_image = args.MODEL | ||
self.ai_image = self.ai_image.removeprefix("oci://") | ||
if args.name: | ||
self.name = args.name | ||
else: | ||
self.name = os.path.basename(self.ai_image) | ||
|
||
self.model = model.removeprefix("oci://") | ||
self.args = args | ||
self.exec_args = exec_args | ||
|
||
def gen_container(self): | ||
port_string = "" | ||
if hasattr(self.args, "port"): | ||
port_string = f"PublishPort={self.args.port}" | ||
|
||
name_string = "" | ||
if hasattr(self.args, "name") and self.args.name: | ||
name_string = f"ContainerName={self.args.name}" | ||
|
||
outfile = self.name + ".container" | ||
print(f"Generating quadlet file: {outfile}") | ||
volume = self.gen_volume() | ||
with open(outfile, 'w') as c: | ||
c.write( | ||
f"""\ | ||
[Unit] | ||
Description=RamaLama {self.model} AI Model Service | ||
After=local-fs.target | ||
[Container] | ||
AddDevice=-/dev/dri | ||
AddDevice=-/dev/kfd | ||
Exec={" ".join(self.exec_args)} | ||
Image={default_image()} | ||
{volume} | ||
{name_string} | ||
{port_string} | ||
[Install] | ||
# Start by default on boot | ||
WantedBy=multi-user.target default.target | ||
""" | ||
) | ||
|
||
def gen_volume(self): | ||
if os.path.exists(self.model): | ||
return f"Volume={self.model}:/mnt/models/model.file,ro:Z" | ||
|
||
outfile = self.name + ".volume" | ||
|
||
self.gen_image() | ||
print(f"Generating quadlet file: {outfile} ") | ||
with open(outfile, 'w') as c: | ||
c.write( | ||
f"""\ | ||
[Volume] | ||
Driver=image | ||
Image={self.name}.image | ||
""" | ||
) | ||
return f"Mount=type=volume,source={self.name}.volume,dest=/mnt/models,ro" | ||
|
||
def gen_image(self): | ||
outfile = self.name + ".image" | ||
print(f"Generating quadlet file: {outfile} ") | ||
with open(outfile, 'w') as c: | ||
c.write( | ||
f"""\ | ||
[Image] | ||
Image={self.ai_image} | ||
""" | ||
) |
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