Skip to content
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

Load nweight-user-features as resource file #745

Open
jnsrnhld opened this issue Sep 27, 2024 · 0 comments
Open

Load nweight-user-features as resource file #745

jnsrnhld opened this issue Sep 27, 2024 · 0 comments

Comments

@jnsrnhld
Copy link

Hi,

I wondered why the sparkbench/graph resource nweight-user-features is not loaded as a resource. The resource is packaged together with the .jar anyway, so I'd propose something like this:

NWeightDataGenerator.scala

[...]
def loadModel(modelPath: String, sc: SparkContext, partitions: Int): MatrixFactorizationModel = {
    getClass.getResourceAsStream(modelPath) match {
      case null => throw new FileNotFoundException(modelPath)
      case stream =>
        val in = new DataInputStream(stream)
        val weights = new Array[(Int, Double)](MAX_ID)
        for (i <- weights.indices) {
          val w = in.readFloat()
          weights(i) = (i, w)
        }
        in.close()

        val userFeatures = sc.parallelize(weights, math.max(400, partitions)).map { case (i, w) =>
          (i, Array(w))
        }
        val userFeaturesPartitioned = userFeatures.partitionBy(new HashPartitioner(partitions))
        userFeaturesPartitioned.cache()
        // Model matrix is symmetric, so productFeatures is the same with userFeatures
        new MatrixFactorizationModel(1, userFeaturesPartitioned, userFeaturesPartitioned)
    }
 }
[...]

and the workload config:

nweight.conf

[...]
hibench.nweight.model_path	            /nweight-user-features
[...]

This could be beneficial in cases where the execution environment does not contain the hibench directory itself.

@jnsrnhld jnsrnhld changed the title Load /nweight-user-features as resource file Load nweight-user-features as resource file Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant