-
Notifications
You must be signed in to change notification settings - Fork 843
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
Fix interpretation of filename from model archive URL #2416
Merged
namannandan
merged 1 commit into
pytorch:master
from
namannandan:naman-mar-url-filename-fix
Jun 15, 2023
Merged
Changes from all commits
Commits
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
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
46 changes: 46 additions & 0 deletions
46
frontend/archive/src/test/java/org/pytorch/serve/archive/utils/ArchiveUtilsTest.java
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,46 @@ | ||
package org.pytorch.serve.archive.utils; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
public class ArchiveUtilsTest { | ||
@Test | ||
public void testGetFilenameFromUrlWithFilename() { | ||
String testFilename = "resnet-18.mar"; | ||
String expectedFilename = "resnet-18.mar"; | ||
Assert.assertEquals(ArchiveUtils.getFilenameFromUrl(testFilename), expectedFilename); | ||
} | ||
|
||
@Test | ||
public void testGetFilenameFromUrlWithFilepath() { | ||
String testFilepath = "/home/ubuntu/model_store/resnet-18.mar"; | ||
String expectedFilename = "resnet-18.mar"; | ||
Assert.assertEquals(ArchiveUtils.getFilenameFromUrl(testFilepath), expectedFilename); | ||
} | ||
|
||
@Test | ||
public void testGetFilenameFromUrlWithUrl() { | ||
String testFileUrl = "https://torchserve.pytorch.org/mar_files/resnet-18.mar"; | ||
String expectedFilename = "resnet-18.mar"; | ||
Assert.assertEquals(ArchiveUtils.getFilenameFromUrl(testFileUrl), expectedFilename); | ||
} | ||
|
||
@Test | ||
public void testGetFilenameFromUrlWithS3PresignedUrl() { | ||
String testFileUrl = | ||
"https://test-account.s3.us-west-2.amazonaws.com/mar_files/resnet-18.mar?" | ||
+ "response-content-disposition=inline&X-Amz-Security-Token=%2Ftoken%2F" | ||
+ "&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230614T182131Z&X-Amz-SignedHeaders=host" | ||
+ "&X-Amz-Expires=43200&X-Amz-Credential=%2Fcredential%2F" | ||
+ "&X-Amz-Signature=%2Fsignature%2F"; | ||
String expectedFilename = "resnet-18.mar"; | ||
Assert.assertEquals(ArchiveUtils.getFilenameFromUrl(testFileUrl), expectedFilename); | ||
} | ||
|
||
@Test | ||
public void testGetFilenameFromUrlWithInvalidUrl() { | ||
String testFileUrl = "resnet-18.mar/"; | ||
String expectedFilename = ""; | ||
Assert.assertEquals(ArchiveUtils.getFilenameFromUrl(testFileUrl), expectedFilename); | ||
} | ||
} |
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
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.
FilenameUtils.getName is used to extract the mar filename from the url. it is correct function. The original url is passed to function ArchiveUtils.downloadArchive.
The issue most likely happen in downloadArchive.
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.
Yes, this is correct, the call path is ModelArchive.downloadModel -> ArchiveUtils.downloadArchive -> HttpUtils.copyURLToFile -> FileUtils.copyURLToFile.
org.apache.commons.io.FileUtils.copyURLToFile
throwsIOException
because of thedestination
we pass to it in the case of S3 presigned URL.For example, in the current implementation, in case of S3 pre-signed URL, we call
org.apache.commons.io.FileUtils.copyURLToFile
with the following arguments:source:
https://test-account.s3.us-west-2.amazonaws.com/mar_files/resnet-18.mar?response-content-disposition=inline&X-Amz-Security-Token=token&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230614T182131Z&X-Amz-SignedHeaders=host&X-Amz-Expires=43200&X-Amz-Credential=credential&X-Amz-Signature=signature
destination:
resnet-18.mar?response-content-disposition=inline&X-Amz-Security-Token=token&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230614T182131Z&X-Amz-SignedHeaders=host&X-Amz-Expires=43200&X-Amz-Credential=credential&X-Amz-Signature=signature
and this fails with
IOException
.For testing, I hardcoded the
destination
in the HttpUtils.copyURLToFile toresnet-18.mar
and the download succeeded.Therefore, I've fixed the the implementation to correctly identify
filename
from model archive URL that contains additional parameters after the filename inModelArchive.java
which is eventually passed toorg.apache.commons.io.FileUtils.copyURLToFile
.With the fix in this PR, the arguments are passed correctly:
source:
https://test-account.s3.us-west-2.amazonaws.com/mar_files/resnet-18.mar?response-content-disposition=inline&X-Amz-Security-Token=token&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230614T182131Z&X-Amz-SignedHeaders=host&X-Amz-Expires=43200&X-Amz-Credential=credential&X-Amz-Signature=signature
destination:
resnet-18.mar