Skip to content

feat: implement preflight - #502

Merged
logan-wrld merged 27 commits into
mainfrom
feat/preflight-logan
Feb 4, 2025
Merged

feat: implement preflight#502
logan-wrld merged 27 commits into
mainfrom
feat/preflight-logan

Conversation

@logan-wrld

@logan-wrld logan-wrld commented Jan 29, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR implements a new pre-flight check system for Lilypad resource providers. The pre-flight check verifies essential requirements including GPU availability, Docker runtime, and system resources before a provider joins the network.

This pull request makes the following changes:

  • Implemented GPU detection and validation using nvidia-smi
  • Added Docker runtime verification
  • Introduced system requirements check (1GB RAM minimum
  • Added graceful handling for non-GPU environments
  • Enhanced logging system for pre-flight status and success messages

These changes are made to ensure a Resource Provider(s) is prepared to run a Lilypad Module

Task/Issue reference

First iteration of preflight!

Test plan

You can test this locally within the dev environment.

Details (optional)

Add any additional details that will help to review this pull request.

Related issues or PRs (optional)

A previous PR that served as inspiration: #433

@logan-wrld
logan-wrld requested a review from a team as a code owner January 29, 2025 00:34
@cla-bot cla-bot Bot added the cla-signed label Jan 29, 2025
@logan-wrld logan-wrld changed the title Feat/preflight logan feat/preflight logan Jan 29, 2025
@logan-wrld logan-wrld changed the title feat/preflight logan noryev/feat-preflight-checks Jan 29, 2025
@logan-wrld logan-wrld changed the title noryev/feat-preflight-checks feat: implement preflight Jan 29, 2025

@narbs91 narbs91 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff @noryev ! Just a couple small comments/suggestions

Comment on lines +48 to +49
Message: "NVIDIA runtime test failed",
Error: err,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Ordering of these is different in comparison to the lines above. Also maybe a worth adding a formatted error like the others?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the ordering and per Brians comments, I also moved these structs to preflight.go to get rid of the types.toml

Comment thread pkg/resourceprovider/preflight/gpu.go Outdated
Comment on lines +58 to +71
fields := strings.Split(record, ", ")
if len(fields) != 4 {
continue
}

memoryStr := strings.Split(fields[2], " ")[0]
memoryMiB, _ := strconv.ParseInt(memoryStr, 10, 64)

gpu := GPUInfo{
UUID: strings.TrimSpace(fields[0]),
Name: strings.TrimSpace(fields[1]),
MemoryTotal: memoryMiB,
DriverVersion: strings.TrimSpace(fields[3]),
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe would be cleaner if you had a mapper function that took in a record and spit out a gpu object? Also, do we know for certain that the fields won't be blank?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TY! Totally agree, I have moved that parsing code into its own parseGPURecord func that is cleaner. WDYT? d1b7d78

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added better error handling if the fields are blank too

Comment thread pkg/resourceprovider/preflight/gpu.go Outdated
Comment on lines +13 to +34
type preflightChecker struct {
gpuInfo []GPUInfo
}

type GPUCheckConfig struct {
Required bool
MinGPUs int
MinMemory int64
Capabilities []string
}

func checkNvidiaSMI() error {
_, err := exec.LookPath("nvidia-smi")
return err
}

type nvidiaSmiResponse struct {
UUID string
Name string
MemoryTotal string
DriverVersion string
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for leaving these in this file vs putting them in preflight/types?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would have made more sense! For cleaner code, I moved types.go into preflight.go per Brians instructions getting rid of the types.go.

Comment thread pkg/resourceprovider/preflight/types.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move these types into preflight.go? Having the types alongside the code that uses them is a better code organization pattern.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Thank you for the recommendation!

Comment thread pkg/options/resource-provider.go Outdated
Comment on lines +22 to +28
Preflight: preflight.PreflightConfig{
GPU: struct {
Required bool
Enabled bool
MinMemoryGB int64
Capabilities []string
}{
Required: false, // Enable to require GPU
Enabled: true, // Enable checks to detect if GPU exists
MinMemoryGB: 1, // Minimum memory required for GPU (we can match this with the resourceOffer)
},
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed these configs. It looks like this may run fine on CPU-only and GPU machines, and doesn't significantly slow down start up times. For now, let's leave the preflight check enabled in all cases, and we can see if there is a motivation to make it configurable.

The Required config can also be removed now that the preflight check works fine on any machine.

The MinMemoryGB can be moved to the code that uses it and hardcoded. In the future, there may be a reason a resource provider would want to configure this, but for a first pass we can hard code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the toggle(s) so now preflight is always running with or without a GPU within the commits here: d14be6b
Secondly, I assigned the MinMemoryGB value to a variable thats hardcoded in the code. 7b42625

@logan-wrld
logan-wrld force-pushed the feat/preflight-logan branch from 9cbff18 to 2e56993 Compare February 3, 2025 18:29
Comment thread pkg/options/resource-provider.go Outdated
Comment on lines +22 to +28
Preflight: preflight.PreflightConfig{
GPU: struct {
MinMemoryGB int64
}{
MinMemoryGB: preflight.RequiredGPUMemoryGB,
},
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to the preflight package. We add items to the options package when they are configurable by users.

Co-authored-by: logan <logan.lentz1@gmail.com>
bgins and others added 4 commits February 3, 2025 15:30

@narbs91 narbs91 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

web3SDK *web3.Web3SDK
options ResourceProviderOptions
controller *ResourceProviderController
gpuInfo []preflight.GPUInfo

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using this?

logan-wrld and others added 4 commits February 4, 2025 11:35
Co-authored-by: logan <logan.lentz1@gmail.com>
Co-authored-by: logan <logan.lentz1@gmail.com>
Co-authored-by: logan <logan.lentz1@gmail.com>

@bgins bgins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Great work on this. 🎉

@logan-wrld

Copy link
Copy Markdown
Contributor Author

TYSM Brian and Narb! I have made sure preflight is working across multiple Resource Provider environments:
Hardware tested:

  • Multiple Apple Silicon RP's
  • Two different NVIDIA GPU enabled RP's

Here is an example preflight logs on a GPU enabled RP
image

@logan-wrld
logan-wrld merged commit 9c2ae59 into main Feb 4, 2025
@logan-wrld
logan-wrld deleted the feat/preflight-logan branch February 4, 2025 21:15
kelindi added a commit that referenced this pull request Feb 11, 2025
* feat: barebones

* feat: Implement preflight checks for GPU and Docker runtime

* feat: Preflight logging and success messages

* chore:  restore comments in [pkg/resourceprovider/resourceprovider.go]

* feat: gpu check + cleanup

* fix: gpu nvidia-smi check

* fix: handle no-GPU case gracefully

* fix: update start method in RP

* chore: remove unused dockerfiles

* chore: restore comments in [pkg/resourceprovider/resourceprovider.go]

* chore: remove comments within [pkg/resourceprovider/resourceprovider.go]

* refactor: removed minimum GPU parameter

* feat: 1gb ram requirement

* refactor: simplify GPU configuration by removing unnecessary parameters

* refactor: enhance GPU info logging and remove types file

* refactor: replace hardcoded GPU memory with default constant

* refactor: improve GPU info parsing and validation in GetGPUInfo

* chore: comments for required GPU VRAM

* refactor: Move preflight checker from interface to struct

Co-authored-by: logan <logan.lentz1@gmail.com>

* chore: Remove preflight check from start function

Co-authored-by: logan <logan.lentz1@gmail.com>

* refactor: Move RunPreflightChecks function to preflight package

Co-authored-by: logan <logan.lentz1@gmail.com>

* refactor: Move preflight config to preflight package

Co-authored-by: logan <logan.lentz1@gmail.com>

* chore: refactor context within resource provider

* chore: remove unused gpuInfo field

* refactor: Make functions and structs private where possible

Co-authored-by: logan <logan.lentz1@gmail.com>

* chore: Exit early when no GPU detected

Co-authored-by: logan <logan.lentz1@gmail.com>

* chore: Improve failed to parse GPU string error

Co-authored-by: logan <logan.lentz1@gmail.com>

---------

Co-authored-by: Brian Ginsburg <gins@brianginsburg.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants